GRM-37: refactor: Split CI scripts, fix release PYTHONPATH, dynamic runner discovery

This commit is contained in:
2026-06-21 20:44:39 +00:00
parent 56eb241b77
commit 5511cba1b0
38 changed files with 908 additions and 422 deletions
+25 -25
View File
@@ -1,4 +1,4 @@
"""Unit tests for scripts/molecule_ci_guard.py."""
"""Unit tests for scripts/ci/molecule_ci_guard.py."""
from __future__ import annotations
@@ -10,7 +10,7 @@ from unittest.mock import MagicMock, patch
import pytest
import requests
from scripts.molecule_ci_guard import (
from scripts.ci.molecule_ci_guard import (
any_other_runner_failed,
build_env_for_pair,
build_molecule_cmd,
@@ -22,7 +22,7 @@ from scripts.molecule_ci_guard import (
class TestGetRunningJobs:
def test_returns_jobs(self) -> None:
with patch("scripts.molecule_ci_guard.requests.get") as mock_get:
with patch("scripts.ci.molecule_ci_guard.requests.get") as mock_get:
mock_response = MagicMock()
mock_response.json.return_value = {
"jobs": [
@@ -38,7 +38,7 @@ class TestGetRunningJobs:
mock_get.assert_called_once()
def test_raises_on_request_error(self) -> None:
with patch("scripts.molecule_ci_guard.requests.get") as mock_get:
with patch("scripts.ci.molecule_ci_guard.requests.get") as mock_get:
mock_get.side_effect = requests.RequestException("boom")
with pytest.raises(requests.RequestException):
get_running_jobs("https://gitea.example", "owner", "repo", "token", 123)
@@ -107,7 +107,7 @@ class TestPollForOtherFailures:
]
return []
with patch("scripts.molecule_ci_guard.get_running_jobs") as mock_get_jobs:
with patch("scripts.ci.molecule_ci_guard.get_running_jobs") as mock_get_jobs:
mock_get_jobs.side_effect = side_effect
stop_event.is_set.side_effect = [False, False]
stop_event.wait.return_value = True
@@ -130,7 +130,7 @@ class TestPollForOtherFailures:
stop_event = MagicMock()
failed_event = MagicMock()
with patch("scripts.molecule_ci_guard.get_running_jobs") as mock_get_jobs:
with patch("scripts.ci.molecule_ci_guard.get_running_jobs") as mock_get_jobs:
mock_get_jobs.side_effect = requests.RequestException("boom")
stop_event.is_set.side_effect = [False, True]
stop_event.wait.return_value = True
@@ -155,7 +155,7 @@ class TestCli:
from click.testing import CliRunner
with (
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("time.sleep"),
):
proc = MagicMock()
@@ -172,7 +172,7 @@ class TestCli:
from click.testing import CliRunner
with (
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("time.sleep"),
):
proc = MagicMock()
@@ -202,9 +202,9 @@ class TestCli:
},
clear=True,
),
patch("scripts.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.molecule_ci_guard.get_running_jobs") as mock_get_jobs,
patch("scripts.ci.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.get_running_jobs") as mock_get_jobs,
patch("time.sleep"),
):
mock_get_jobs.return_value = [
@@ -225,7 +225,7 @@ class TestCli:
from click.testing import CliRunner
with (
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("time.sleep", side_effect=KeyboardInterrupt),
patch("os.killpg") as mock_killpg,
patch("os.getpgid") as mock_getpgid,
@@ -270,9 +270,9 @@ class TestCli:
},
clear=True,
),
patch("scripts.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("scripts.ci.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("os.killpg") as mock_killpg,
patch("os.getpgid") as mock_getpgid,
patch("time.sleep", side_effect=lambda x: real_sleep(0.1)),
@@ -307,9 +307,9 @@ class TestCli:
},
clear=True,
),
patch("scripts.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.molecule_ci_guard.get_running_jobs") as mock_get_jobs,
patch("scripts.ci.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.get_running_jobs") as mock_get_jobs,
patch("time.sleep", side_effect=lambda x: real_sleep(0.05)),
):
mock_get_jobs.return_value = [{"name": "molecule-tests (1)", "conclusion": "success"}]
@@ -351,9 +351,9 @@ class TestCli:
},
clear=True,
),
patch("scripts.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("scripts.ci.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("os.killpg") as mock_killpg,
patch("os.getpgid") as mock_getpgid,
patch("time.sleep", side_effect=lambda x: real_sleep(0.1)),
@@ -398,9 +398,9 @@ class TestCli:
},
clear=True,
),
patch("scripts.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("scripts.ci.molecule_ci_guard.POLL_INTERVAL", 0.01),
patch("scripts.ci.molecule_ci_guard.subprocess.Popen") as mock_popen,
patch("scripts.ci.molecule_ci_guard.get_running_jobs", side_effect=get_jobs_side_effect),
patch("os.killpg") as mock_killpg,
patch("os.getpgid") as mock_getpgid,
patch("time.sleep", side_effect=lambda x: real_sleep(0.1)),
@@ -418,7 +418,7 @@ class TestCli:
def test_main_module_block() -> None:
import scripts.molecule_ci_guard as mg
import scripts.ci.molecule_ci_guard as mg
with open(mg.__file__) as f:
source = f.read()