test: add coverage for monitor/vm/winrm to reach 90%% gate
Lint / pssa (push) Successful in 35s
Lint / python (push) Successful in 42s

Bring monitor.py 49->99%%, vm.py 79->98%%, winrm.py 76->100%%. Total project coverage 80.10%% -> 90.69%%, satisfying the 90%% gate set in commit 451a61c.
This commit is contained in:
2026-05-14 23:14:08 +02:00
parent 451a61c6a1
commit b2b31f4b6e
4 changed files with 974 additions and 0 deletions
+82
View File
@@ -189,6 +189,88 @@ def test_vm_new_pascal_case_aliases(
assert backend.calls[0]["snapshot"] == "Custom"
def test_vm_new_backend_unavailable(
monkeypatch: pytest.MonkeyPatch, fake_template: Path, tmp_path: Path
) -> None:
from ci_orchestrator.backends.errors import BackendNotAvailable
base = tmp_path / "build-vms"
def _raise(_v: Any) -> Any:
raise BackendNotAvailable("no vmrun")
monkeypatch.setattr(vm_module, "_make_backend", _raise)
result = CliRunner().invoke(
cli,
[
"vm", "new",
"--template", str(fake_template),
"--clone-base-dir", str(base),
"--job-id", "novm",
],
)
assert result.exit_code != 0
assert "vmrun unavailable" in result.output
def test_vm_new_partial_clone_dir_cleaned(
monkeypatch: pytest.MonkeyPatch, fake_template: Path, tmp_path: Path
) -> None:
"""Backend creates the partial dir then fails -> dir is removed."""
base = tmp_path / "build-vms"
class _B:
def clone_linked(
self, template: str, snapshot: str, name: str,
destination: str | None = None,
) -> Any:
assert destination is not None
Path(destination).parent.mkdir(parents=True, exist_ok=True)
(Path(destination).parent / "stale.txt").write_text("x")
raise BackendOperationFailed("clone", 1, "boom")
monkeypatch.setattr(vm_module, "_make_backend", lambda _v: _B())
result = CliRunner().invoke(
cli,
[
"vm", "new",
"--template", str(fake_template),
"--clone-base-dir", str(base),
"--job-id", "partial",
],
)
assert result.exit_code != 0
assert "clone failed" in result.output
assert not any(p.is_dir() and "partial" in p.name for p in base.iterdir())
def test_vm_new_backend_success_but_missing_vmx(
monkeypatch: pytest.MonkeyPatch, fake_template: Path, tmp_path: Path
) -> None:
"""Backend reports success but VMX file isn't there -> ClickException."""
base = tmp_path / "build-vms"
class _B:
def clone_linked(
self, template: str, snapshot: str, name: str,
destination: str | None = None,
) -> VmHandle:
return VmHandle(identifier=str(destination), name=name)
monkeypatch.setattr(vm_module, "_make_backend", lambda _v: _B())
result = CliRunner().invoke(
cli,
[
"vm", "new",
"--template", str(fake_template),
"--clone-base-dir", str(base),
"--job-id", "ghost",
],
)
assert result.exit_code != 0
assert "clone VMX is missing" in result.output
def test_vm_new_creates_base_dir(
monkeypatch: pytest.MonkeyPatch, fake_template: Path, tmp_path: Path
) -> None: