From 00bac197052c5b6b9a277eff20d27b5775ceb2a4 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 22 Nov 2026 20:09:08 +0000 Subject: [PATCH] ci(molecule): stop running every scenario for files no scenario reads A pull request ran every scenario when it changed the selector itself, which happened whenever a new file was added to its IGNORED list. Molecule runs the base branch's copy, so the pull request's copy is never exercised by a scenario. Ignore it, nested AGENTS.md files, role READMEs, .python-version and scripts/lock-requirements.sh. Assisted-by: Claude Code:claude-opus-5-5 --- scripts/select_molecule_scenarios.py | 10 ++++--- .../scripts/test_select_molecule_scenarios.py | 27 ++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/scripts/select_molecule_scenarios.py b/scripts/select_molecule_scenarios.py index 9691d15..0f15e47 100644 --- a/scripts/select_molecule_scenarios.py +++ b/scripts/select_molecule_scenarios.py @@ -38,8 +38,8 @@ nothing tested. A role whose directory is gone (the role was deleted) selects no The workflow runs this script from the base branch's copy, not the pull request's, so a pull request cannot edit the rules it is judged by (the same reason lint.yml runs -check_bot_pr_diff.py from origin/main). A change to this file therefore selects everything -under the base copy's rules, because the file is not on the IGNORED list. +check_bot_pr_diff.py from origin/main). No scenario runs the pull request's copy, so this file +is on the IGNORED list: its unit tests test it, and the push run after the merge runs it. Exit codes: 0 ok (an empty selection from an all-ignored diff is ok), 1 no scenario exists at all, or a changed role has none, 2 bad usage. Notices go to stderr as `::notice::` lines, with @@ -63,7 +63,8 @@ IGNORED = ( "SECURITY.md", "GLOSSARY.md", "AGENTS.md", - "roles/AGENTS.md", + "*/AGENTS.md", + "roles/*/README.md", "CODEOWNERS", "CHANGELOG.rst", "COPYING", @@ -75,6 +76,7 @@ IGNORED = ( ".ansible-lint", ".ansible-lint-ignore", ".pre-commit-config.yaml", + ".python-version", "requirements-dev.txt", "requirements-dev.lock", "ruff.toml", @@ -100,6 +102,8 @@ IGNORED = ( "scripts/ansible-test-sanity.sh", "scripts/dev-setup.sh", "scripts/reuse_lint.py", + "scripts/lock-requirements.sh", + "scripts/select_molecule_scenarios.py", ) diff --git a/tests/scripts/test_select_molecule_scenarios.py b/tests/scripts/test_select_molecule_scenarios.py index fbfbd1f..2a69253 100644 --- a/tests/scripts/test_select_molecule_scenarios.py +++ b/tests/scripts/test_select_molecule_scenarios.py @@ -162,6 +162,32 @@ class SelectTest(unittest.TestCase): chosen, _reason = sel.select(ALL, ["AGENTS.md"]) self.assertEqual(chosen, []) + def test_nested_agent_guidance_selects_nothing(self): + chosen, _reason = self.select( + [ + ".gitea/workflows/AGENTS.md", + "scripts/AGENTS.md", + "roles/docker/AGENTS.md", + ], + ) + self.assertEqual(chosen, []) + + def test_role_readme_selects_nothing(self): + # A role's README is documentation; its scenarios and its users' do not read it. + chosen, _reason = self.select(["roles/docker/README.md"]) + self.assertEqual(chosen, []) + + def test_selector_and_dev_python_select_nothing(self): + # Molecule runs the base copy of the selector and the runner's own venv. + chosen, _reason = self.select( + [ + "scripts/select_molecule_scenarios.py", + "scripts/lock-requirements.sh", + ".python-version", + ], + ) + self.assertEqual(chosen, []) + def test_issue_and_pull_request_templates_select_nothing(self): # Gitea reads them for its web forms; no scenario does, and they are not shipped. chosen, _reason = self.select( @@ -184,7 +210,6 @@ class SelectTest(unittest.TestCase): "plugins/modules/x.py", "extensions/molecule/image-smoke/molecule.yml", ".gitea/workflows/molecule.yml", - "scripts/select_molecule_scenarios.py", "tests/unit/x.py", "new_top_level_file", "roles/README.md", -- 2.43.0