feat(cfold): canonicalize custom test layout
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
autonomic-bot
2026-06-12 16:08:18 +00:00
parent 87928a9096
commit 44e02425ab
110 changed files with 306 additions and 241 deletions

View File

@ -1,45 +0,0 @@
"""Shared mailu helpers — headless mailbox provisioning via the admin container's `flask mailu` CLI.
mailu's admin container ships the management CLI (`flask mailu domain|user|alias|config-export ...`),
the canonical headless way to provision mail objects. We exec it via the harness (service="admin").
The primary MAIL_DOMAIN is auto-created at boot; `flask mailu domain ... || true` is idempotent.
"""
from __future__ import annotations
import json
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
from harness import lifecycle # noqa: E402
def flask_mailu(domain: str, shell_cmd: str) -> str:
"""Run a `flask mailu ...` shell command in the admin container; return stdout."""
return lifecycle.exec_in_app(domain, ["sh", "-c", shell_cmd], service="admin")
def ensure_domain(domain: str, mail_domain: str) -> None:
# idempotent: the primary domain is auto-created; tolerate "already exists"
flask_mailu(domain, f"flask mailu domain {mail_domain} || true")
def create_user(domain: str, local: str, mail_domain: str, password: str) -> str:
email = f"{local}@{mail_domain}"
flask_mailu(domain, f"flask mailu user {local} {mail_domain} '{password}'")
return email
def config_export(domain: str) -> dict:
"""`flask mailu config-export --json` → parsed dict (keys: domain/user/alias/relay)."""
out = flask_mailu(domain, "flask mailu config-export --json")
# Be robust to any leading banner: extract the JSON object.
start = out.find("{")
end = out.rfind("}")
assert start != -1 and end != -1, f"config-export produced no JSON: {out[:200]!r}"
return json.loads(out[start : end + 1])
def user_emails(cfg: dict) -> list[str]:
return [u.get("email") for u in cfg.get("user", [])]

View File

@ -1,21 +0,0 @@
"""mailu — health/readiness functional test (Phase 2).
SOURCE: no recipe-maintainer corpus exists for mailu (P2 vacuous — see PARITY.md). The nginx front
serves `/` (301 → /webmail) once the stack is up; this is the canonical "is mailu serving" signal.
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
from harness import http as harness_http # noqa: E402
def test_mailu_front_serves(live_app):
url = f"https://{live_app}/"
status, _ = harness_http.retry_http_get(
url, expect_status=(200, 301, 302), max_wait=120, interval=5
)
assert status in (200, 301, 302), f"GET {url} HTTP {status} (mailu front not serving)"

View File

@ -1,54 +0,0 @@
"""mailu — recipe-specific functional test #2 (Phase 2 P3, the characteristic end-to-end mail flow).
Provision a mailbox, INJECT a uniquely-marked message to it via the postfix container's local
`sendmail` (locally-originated → not greylisted, no auth/TLS needed), then VERIFY it was DELIVERED
and STORED by polling dovecot's `doveadm search` in the imap container. This is mailu's defining
behaviour (it is a mail server): a real postfix → rspamd → dovecot deliver→store→fetch round-trip,
not an API/health stand-in.
We use the in-container mail tools (sendmail/doveadm) rather than the host network ports because the
TLS_FLAVOR=notls deploy makes dovecot refuse plaintext auth over the network (143) — the in-container
path exercises the same delivery/storage stack without that constraint, and avoids rspamd greylisting
of network senders.
"""
from __future__ import annotations
import os
import sys
import time
import uuid
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
import _mailu # noqa: E402
from harness import lifecycle # noqa: E402
def test_send_and_receive_mail(live_app):
mail_domain = live_app
local = "ccci-flow-" + uuid.uuid4().hex[:8]
password = "CcCi-" + uuid.uuid4().hex[:16] + "-Aa1!"
_mailu.ensure_domain(live_app, mail_domain)
email_addr = _mailu.create_user(live_app, local, mail_domain, password)
marker = "ccci-mailflow-" + uuid.uuid4().hex
sender = f"admin@{mail_domain}"
# Inject via the postfix container's local sendmail (locally-originated; no greylist/auth/TLS).
msg = f"From: {sender}\\nTo: {email_addr}\\nSubject: {marker}\\n\\nbody {marker}\\n"
inject = f"printf '{msg}' | sendmail -f {sender} {email_addr}"
lifecycle.exec_in_app(live_app, ["sh", "-c", inject], service="smtp")
# Poll dovecot for the stored message (INBOX, then Junk in case rspamd files it).
deadline = time.time() + 150
while time.time() < deadline:
for box in ("INBOX", "Junk"):
query = f"doveadm search -u '{email_addr}' mailbox {box} " f"header subject '{marker}'"
out = lifecycle.exec_in_app(live_app, ["sh", "-c", query], service="imap")
if out.strip(): # a non-empty result = "<mailbox-guid> <uid>" → message stored
return
time.sleep(5)
raise AssertionError(
f"mail with subject {marker!r} injected to {email_addr} was not delivered/stored "
f"(doveadm search found nothing in INBOX/Junk within the postfix→rspamd→dovecot window)"
)

View File

@ -1,29 +0,0 @@
"""mailu — recipe-specific functional test #1 (Phase 2 P3 §4.3 create-an-object + read-back).
Create a mailbox (the characteristic mailu object) via the admin CLI, then read it back from the
authoritative config export and assert it is present. Real create→persist→read-back, not health-only.
"""
from __future__ import annotations
import os
import sys
import uuid
sys.path.insert(0, os.path.dirname(__file__))
import _mailu # noqa: E402
def test_create_mailbox_and_read_back(live_app):
mail_domain = live_app # recipe_meta sets MAIL_DOMAIN = the per-run domain
local = "ccci-" + uuid.uuid4().hex[:8]
password = "CcCi-" + uuid.uuid4().hex[:16] + "-Aa1!"
_mailu.ensure_domain(live_app, mail_domain)
email = _mailu.create_user(live_app, local, mail_domain, password)
cfg = _mailu.config_export(live_app)
emails = _mailu.user_emails(cfg)
assert (
email in emails
), f"created mailbox {email} not present in mailu config-export users {emails}"