Three major improvements: 1. Rootless Docker refactor: Removes docker/binary modes, unifies to rootless Docker with per-runner system users. Each runner gets its own rootless Docker daemon, systemd user service, and isolated environment. Simplifies CLI (removes --mode option), Ansible role (single code path), and molecule scenarios (removes binary scenario). 2. Auto-merge fix: Fixes status check context mismatch in branch protection (was requiring "lint", "unit-tests", "molecule-tests" but actual contexts are "CI / quality", "CI / molecule-tests*"). Adds retry/wait logic to auto_merge.py that polls commit statuses for up to 15 minutes before attempting merge, eliminating the chicken-and-egg problem where auto-merge would fail because CI hadn't completed yet. 3. Molecule platform matrix: Adds OS platform matrix to CI — all 6 scenarios now run on all 4 supported OSes (ubuntu-2204, ubuntu-2404, debian-12, archlinux) = 24 test pairs distributed across 3 parallel runners. Updates distribute_molecule.py to distribute (scenario, platform) pairs. Updates Makefile with molecule-all target for local multi-platform testing. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
100 lines
3.5 KiB
Python
100 lines
3.5 KiB
Python
"""Unit tests for the runner registry."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from gitea_runner_manager.exceptions import GRMError
|
|
from gitea_runner_manager.registry import RunnerRegistry
|
|
|
|
|
|
class TestRunnerRegistry:
|
|
def test_init_default_path(self) -> None:
|
|
reg = RunnerRegistry()
|
|
assert reg._path == Path.home() / ".local" / "share" / "grm" / "runners.json"
|
|
|
|
def test_add_and_get(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add(
|
|
"r1",
|
|
host="10.0.0.1",
|
|
user="ubuntu",
|
|
key="/key",
|
|
gitea_url="https://git.example.com",
|
|
labels="docker:docker://alpine:latest",
|
|
)
|
|
info = reg.get("r1")
|
|
assert info is not None
|
|
assert info["host"] == "10.0.0.1"
|
|
assert info["user"] == "ubuntu"
|
|
assert info["key"] == "/key"
|
|
assert info["gitea_url"] == "https://git.example.com"
|
|
assert info["labels"] == "docker:docker://alpine:latest"
|
|
assert "created_at" in info
|
|
|
|
def test_add_without_labels(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add("r1", host="10.0.0.1", user="ubuntu")
|
|
info = reg.get("r1")
|
|
assert info is not None
|
|
assert info["labels"] is None
|
|
|
|
def test_get_missing(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
assert reg.get("missing") is None
|
|
|
|
def test_remove(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add("r1", host="10.0.0.1", user="ubuntu")
|
|
reg.remove("r1")
|
|
assert reg.get("r1") is None
|
|
|
|
def test_list(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add("r1", host="10.0.0.1", user="ubuntu")
|
|
reg.add("r2", host="10.0.0.2", user="root")
|
|
runners = reg.list()
|
|
assert len(runners) == 2
|
|
assert runners["r1"]["host"] == "10.0.0.1"
|
|
assert runners["r2"]["host"] == "10.0.0.2"
|
|
|
|
def test_update(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add("r1", host="10.0.0.1", user="ubuntu")
|
|
reg.update("r1", host="10.0.0.2")
|
|
info = reg.get("r1")
|
|
assert info is not None
|
|
assert info["host"] == "10.0.0.2"
|
|
assert info["user"] == "ubuntu"
|
|
|
|
def test_update_missing(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
with pytest.raises(GRMError, match="not found in registry"):
|
|
reg.update("missing", host="10.0.0.1")
|
|
|
|
def test_persistence(self, tmp_path: Path) -> None:
|
|
path = tmp_path / "runners.json"
|
|
reg1 = RunnerRegistry(path)
|
|
reg1.add("r1", host="10.0.0.1", user="ubuntu")
|
|
reg2 = RunnerRegistry(path)
|
|
info = reg2.get("r1")
|
|
assert info is not None
|
|
assert info["host"] == "10.0.0.1"
|
|
|
|
def test_corrupt_file(self, tmp_path: Path) -> None:
|
|
path = tmp_path / "runners.json"
|
|
path.write_text("not json")
|
|
reg = RunnerRegistry(path)
|
|
assert reg.list() == {}
|
|
|
|
def test_list_returns_copy(self, tmp_path: Path) -> None:
|
|
reg = RunnerRegistry(tmp_path / "runners.json")
|
|
reg.add("r1", host="10.0.0.1", user="ubuntu")
|
|
runners = reg.list()
|
|
runners["r1"]["host"] = "modified"
|
|
info = reg.get("r1")
|
|
assert info is not None
|
|
assert info["host"] == "10.0.0.1"
|