57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Hermes gateway tool-environment patch and manifest tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import stat
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
HERMES = ROOT / "services/hermes"
|
|
SCRIPT = HERMES / "scripts/patch_main_wrapper.py"
|
|
|
|
|
|
def _patch_module():
|
|
spec = importlib.util.spec_from_file_location("patch_main_wrapper", SCRIPT)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def _deployment() -> dict:
|
|
return yaml.safe_load((HERMES / "agent-deployment.yaml").read_text())
|
|
|
|
|
|
def test_wrapper_loads_tool_environment_after_s6_restore(tmp_path: Path) -> None:
|
|
module = _patch_module()
|
|
source = tmp_path / "main-wrapper.sh"
|
|
destination = tmp_path / "patched.sh"
|
|
source.write_text("#!/bin/sh\n" + module.BEFORE + "export HOME=/opt/data\n")
|
|
source.chmod(0o755)
|
|
|
|
module.patch(source, destination)
|
|
|
|
patched = destination.read_text()
|
|
assert ". /opt/data/.env" in patched
|
|
assert patched.index(". /opt/data/.env") < patched.index("export HOME=/opt/data")
|
|
assert destination.stat().st_mode & stat.S_IXUSR
|
|
|
|
|
|
def test_gateway_retains_stock_entrypoint_with_patched_wrapper() -> None:
|
|
pod = _deployment()["spec"]["template"]["spec"]
|
|
init = {item["name"]: item for item in pod["initContainers"]}
|
|
containers = {item["name"]: item for item in pod["containers"]}
|
|
|
|
assert "repair-cassandra-kanban" in init
|
|
assert "patch-main-wrapper" in init
|
|
assert containers["hermes"]["command"] == [
|
|
"/init",
|
|
"/opt/hermes/docker/main-wrapper.sh",
|
|
]
|
|
mounts = {item["name"]: item for item in containers["hermes"]["volumeMounts"]}
|
|
assert mounts["main-wrapper-patch"]["subPath"] == "main-wrapper.sh"
|