ci(molecule): run Molecule in the molecule-controller image

Molecule ran in the ci image, so a ci pin bump for a tool only Lint uses selected every
scenario (ADR 0003). The workflow now pins molecule-controller 0.1.0 by digest as
CONTROLLER_IMAGE, the hand-made first pin the ADR calls for.

- The run script checks /opt/molecule-pins.sha256 and installs requirements-molecule.lock
  when a pull request changed a pin file.
- The selector reads CONTROLLER_IMAGE: a controller pin change selects every scenario; a ci
  pin bump touches only lint.yml and build.yml, which are on IGNORED, so it selects none.
- Tests show requirements-molecule.* selects every scenario and requirements-dev.* none.
- Renovate's molecule.yml regex matches CONTROLLER_IMAGE.

Closes #434

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-29 19:25:33 +00:00
1 parent 6e89e4d857
commit 89bd579e87
7 files changed
+58 -32

No files matched your search

@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the ci image's.
"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the molecule-controller
image's.
Run with: python3 -m unittest discover -s tests/scripts
"""
@@ -105,7 +106,7 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
result = self.run_script()
self.assertEqual(result.returncode, 0, result.stderr)
(check,) = self.calls("sha256sum")
self.assertIn("args=--quiet -c /opt/ci-pins.sha256 ", check)
self.assertIn("args=--quiet -c /opt/molecule-pins.sha256 ", check)
self.assertEqual(self.calls("python"), [])
self.assertEqual(self.calls("ansible-galaxy"), [])
self.assertEqual(len(self.calls("ansible")), 1)
@@ -132,8 +133,8 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
)
(pip,) = self.calls("pip")
self.assertIn(
"args=install --quiet --require-hashes -r requirements-dev.lock"
" -r requirements-dev.txt ",
"args=install --quiet --require-hashes -r requirements-molecule.lock"
" -r requirements-molecule.txt ",
pip,
)
galaxy = self.calls("ansible-galaxy")
@@ -206,6 +206,23 @@ class SelectTest(unittest.TestCase):
)
self.assertEqual(chosen, [])
def test_a_ci_pin_bump_in_lint_or_build_selects_nothing(self):
chosen, _reason = self.select(
[".gitea/workflows/lint.yml", ".gitea/workflows/build.yml"]
)
self.assertEqual(chosen, [])
def test_lint_requirements_select_nothing(self):
# requirements-dev.* pin Lint's tools; Molecule's come from requirements-molecule.*.
chosen, _reason = self.select(["requirements-dev.txt", "requirements-dev.lock"])
self.assertEqual(chosen, [])
def test_molecule_requirements_select_everything(self):
# An ansible-core or molecule bump there changes the tools every scenario runs with.
for path in ("requirements-molecule.txt", "requirements-molecule.lock"):
chosen, _reason = self.select([path])
self.assertEqual(chosen, ALL, path)
def test_ignored_does_not_mask_a_role(self):
chosen, _reason = self.select(["docs/x.md", "roles/docker/tasks/main.yml"])
self.assertEqual(chosen, ["roles/docker/molecule/default"])
@@ -660,9 +677,14 @@ class WorkflowPinsTest(unittest.TestCase):
return self.pin(key).split("@sha256:")[0] + "@sha256:" + "0" * 64
def test_the_workflow_has_each_pin_where_the_selector_looks(self):
for key in ("CI_IMAGE", "MOLECULE_IMAGE", "MOLECULE_IMAGE_2604"):
for key in ("CONTROLLER_IMAGE", "MOLECULE_IMAGE", "MOLECULE_IMAGE_2604"):
self.assertEqual(self.edited(self.pin(key), self.bumped(key)), {key}, key)
def test_the_workflow_runs_in_the_controller_image_not_ci(self):
# A ci pin bump must touch only Lint and Build, which IGNORED lists (ADR 0003).
self.assertIn("/mortis/molecule-controller:", self.pin("CONTROLLER_IMAGE"))
self.assertNotIn("/mortis/ci:", self.WORKFLOW)
def test_comments_and_blank_lines_change_nothing(self):
self.assertEqual(self.edited("# Behavioural tests", "# Other words"), set())
self.assertEqual(self.edited("\njobs:\n", "\n\n\njobs:\n"), set())
@@ -772,8 +794,9 @@ class SelectByPinTest(unittest.TestCase):
def test_comments_only_select_nothing(self):
self.assertEqual(self.select(set()), [])
def test_the_ci_image_or_no_analysis_selects_everything(self):
self.assertEqual(self.select({"CI_IMAGE", "MOLECULE_IMAGE"}), ALL)
def test_the_controller_image_or_no_analysis_selects_everything(self):
self.assertEqual(self.select({"CONTROLLER_IMAGE"}), ALL)
self.assertEqual(self.select({"CONTROLLER_IMAGE", "MOLECULE_IMAGE"}), ALL)
self.assertEqual(self.select(None), ALL)
def test_pins_do_not_narrow_another_file(self):