Files
monky-deployd/tests/test_cli.py
T
mdella c966450d8e fix(install): fetch from scm.tikali.ai (public project) — Gitea name is split-horizon inside the estate
Inside the estate gitea.cbs.tikali.net resolves to jump1's RED EIP (10.10.0.175),
which has no HTTP ingress, so backend boxes could not download the install
artefacts from the Gitea mirror (cbs/iac#102). scm.tikali.ai is reachable from
those boxes and the project is now public, so the GitLab generic package
registry becomes the PRIMARY source:

- packaging/install.sh: default source = scm.tikali.ai generic package registry
  (projects/69/packages/generic/monky-deployd/<ver>/...); `--source gitea` /
  MONKY_DEPLOYD_SOURCE=gitea keeps the Gitea release as the off-estate
  alternative; --base-url / MONKY_DEPLOYD_BASE_URL still override the base.
- ansible role defaults: monky_deployd_base_url/_deb_url point at the registry,
  Gitea layout kept as a commented alternative.
- README / docs/OPERATIONS.md / CLAUDE.md / CI comments + release description:
  both locations keep being published (release + release:gitea).
- Version 0.1.1 (the tag gate refuses v* tags whose version != __version__);
  tests compare against __version__ instead of a literal. No agent change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KLB7jieMNRkTsJ2epr4Ds1
2026-09-05 17:57:27 +00:00

103 lines
3.4 KiB
Python

import json
from pathlib import Path
from monky_deployd import __version__, cli
from monky_deployd.agent import EX_OK
def write_cfg(cfg):
lines = [
f"env_id: {cfg.env_id}",
f"site: {cfg.site}",
"transport: system",
"tenancy:",
f" host: {cfg.tenancy.host}",
f" port: {cfg.tenancy.port}",
" scheme: http",
"bao:",
f" addr: {cfg.bao.addr}",
" ca_bundle: none",
f"state_dir: {cfg.state_dir}",
f"bootstrap_path: {cfg.bootstrap_path}",
f"deploy_dir: {cfg.deploy_dir}",
"healthy_timeout_s: 3",
]
Path(cfg.path).write_text("\n".join(lines) + "\n")
return cfg.path
def test_run_once_then_status(bootstrapped, tenancy, fake_docker, capsys):
path = write_cfg(bootstrapped)
assert cli.main(["-c", path, "run", "--once"]) == EX_OK
assert cli.main(["-c", path, "status", "--json"]) == EX_OK
out = json.loads(capsys.readouterr().out)
assert out["in_sync"] is True and out["applied_sha"] == tenancy.desired_sha and out["token_present"] is True
assert out["healthy"] is True and out["containers"][0]["name"] == "see"
assert cli.main(["-c", path, "status"]) == EX_OK
text = capsys.readouterr().out
assert "in sync" in text and "healthy" in text and "hvs." not in text
def test_bootstrap_command(bootstrapped, bao, capsys):
cfg = bootstrapped
path = write_cfg(cfg)
assert cli.main(["-c", path, "bootstrap"]) == EX_OK
assert cfg.token_path.exists() and not Path(cfg.bootstrap_path).exists()
assert cli.main(["-c", path, "bootstrap"]) == EX_OK
assert "already bootstrapped" in capsys.readouterr().out
def test_version_and_bad_config(capsys, tmp_path):
assert cli.main(["version"]) == 0
assert capsys.readouterr().out.strip() == __version__
bad = tmp_path / "c.yaml"
bad.write_text("env_id: nope\nsite: cbs\n")
assert cli.main(["-c", str(bad), "status"]) == 78
assert cli.main(["-c", str(tmp_path / "missing.yaml"), "status"]) == 1
def test_sdk_transport_uses_openziti_monkeypatch(monkeypatch, tmp_path):
"""The sdk transport loads the identity once and dials inside openziti.monkeypatch()."""
import contextlib
import socket
import sys
import types
calls = []
fake = types.ModuleType("openziti")
fake.load = lambda p: calls.append(("load", p)) or object()
@contextlib.contextmanager
def mp():
calls.append(("monkeypatch",))
yield
fake.monkeypatch = mp
monkeypatch.setitem(sys.modules, "openziti", fake)
from monky_deployd.transport import SdkTransport
srv = socket.socket()
srv.bind(("127.0.0.1", 0))
srv.listen(1)
t = SdkTransport(str(tmp_path / "id.json"))
s = t.connect("127.0.0.1", srv.getsockname()[1], 2)
s.close()
srv.close()
assert calls == [("load", str(tmp_path / "id.json")), ("monkeypatch",)]
assert "sdk(identity=" in t.describe()
def test_proxy_transport_refuses_unmapped_hosts():
from monky_deployd.config import from_dict
from monky_deployd.transport import TransportError, build
cfg = from_dict({"env_id": "env-dev-06", "site": "cbs", "transport": "proxy"})
t = build(cfg)
assert t.mapping[("monky.tenancy.deploy", 8081)] == ("127.0.0.1", 18443)
assert t.mapping[("bao.cbs.tikali.net", 8200)] == ("127.0.0.1", 18200)
try:
t.connect("example.com", 443, 1)
raise AssertionError("unmapped host must be refused")
except TransportError:
pass