af60ca446d
The fabledscryer->steward rename had only ever reached host_agent. The other five bundled plugins (http, snmp, traefik, unifi, docker) still imported `from fabledscryer.*` (package no longer exists) and read FABLEDSCRYER_* env vars — so every one of them was broken at import since the original rebrand. CI stayed green only because none are enabled by default and migrations don't import plugin modules. Now that they version in-tree, complete the rename: - fabledscryer.* -> steward.* imports across all five plugins - FABLEDSCRYER_* -> STEWARD_* in plugin migration env.py files - author/repository/homepage + user-facing 'Fabled Scryer' strings -> Steward - snmp/scheduler.py: also drop dead `now`/datetime; record_metric from steward Adds tests/test_no_legacy_names.py — fails if 'scryer'/'roundtable' ever reappear in shipped code (the drift bit twice; this stops a third time). Also clears pre-existing ruff lint debt (unused imports, semicolon statements, mid-file import) surfaced by the new lint lane. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
"""Pure-function tests for install.sh.j2 rendering and agent.py parsing."""
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
from plugins.host_agent.routes import _agent_version, AGENT_SOURCE_PATH
|
|
|
|
|
|
TEMPLATE_DIR = Path(__file__).resolve().parents[3] / "plugins" / "host_agent" / "templates"
|
|
|
|
|
|
def _render(**overrides) -> str:
|
|
env = Environment(loader=FileSystemLoader(str(TEMPLATE_DIR)))
|
|
defaults = dict(
|
|
url="https://r.example",
|
|
token="tok-abc",
|
|
agent_version="1.0.0",
|
|
host_name="testhost",
|
|
host_address="10.0.0.1",
|
|
)
|
|
defaults.update(overrides)
|
|
return env.get_template("install.sh.j2").render(**defaults)
|
|
|
|
|
|
def test_render_contains_token_and_url():
|
|
out = _render()
|
|
assert "tok-abc" in out
|
|
assert "https://r.example" in out
|
|
assert "testhost" in out
|
|
|
|
|
|
def test_render_contains_hardening_directives():
|
|
out = _render()
|
|
for needle in (
|
|
"NoNewPrivileges=yes",
|
|
"ProtectSystem=strict",
|
|
"ProtectHome=yes",
|
|
"PrivateTmp=yes",
|
|
"ReadOnlyPaths=/proc /sys",
|
|
):
|
|
assert needle in out, f"missing {needle}"
|
|
|
|
|
|
def test_render_has_uninstall_branch():
|
|
out = _render()
|
|
assert "--uninstall" in out
|
|
assert "systemctl disable --now steward-agent.service" in out
|
|
|
|
|
|
def test_render_has_systemctl_enable():
|
|
out = _render()
|
|
assert "systemctl enable --now steward-agent.service" in out
|
|
|
|
|
|
def test_render_uses_agent_py_url():
|
|
out = _render()
|
|
assert "/plugins/host_agent/agent.py" in out
|
|
|
|
|
|
def test_rendered_script_passes_sh_n(tmp_path):
|
|
out = _render()
|
|
script = tmp_path / "install.sh"
|
|
script.write_text(out)
|
|
result = subprocess.run(
|
|
["sh", "-n", str(script)], capture_output=True, text=True
|
|
)
|
|
assert result.returncode == 0, f"sh -n failed: {result.stderr}"
|
|
|
|
|
|
def test_agent_version_parses_on_disk_agent():
|
|
assert AGENT_SOURCE_PATH.exists()
|
|
v = _agent_version()
|
|
assert v == "1.0.0"
|