fix(mail-templates): run under Riposte's exec() runner (1.0.1)

The runner execs a script without __file__ or __name__: the Test button
failed on __file__ and render-mail-template never reached main(). The
test no longer imports the renderer, and the renderer calls main()
unconditionally like the other integrations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BJu1jvaug4qY1kMgz8wx41
This commit is contained in:
2026-10-19 08:49:46 +00:00
parent dcf257d887
commit 046810c1f6
3 changed files with 10 additions and 30 deletions
@@ -1,27 +1,8 @@
import json, os, sys
import json
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Nothing to connect to. Riposte runs one script per command through exec(),
# so this cannot import the renderer: it only answers the Test button.
TEMPLATES = ["sla_breach", "incident_notification", "incident_update", "incident_closure",
"action_required", "escalation", "threat_bulletin", "info"]
SAMPLE = "## Sample\n\n**1 ticket** waiting.\n\n| Ticket | Priority |\n|---|---|\n| SOC-1 | {{medium}} |\n\n```\n8.8.8.8\n```"
def main():
try:
import render_mail_template as r
except ImportError:
# The runner ships one script per command: say so instead of failing the Test button.
print(json.dumps({"ok": True, "detail": "No connection to test; render a template to check the output."}))
return
try:
cfg = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
sizes = {}
for name in r.TEMPLATES:
out = r.render(cfg, {"template": name, "subject": "Test", "description": SAMPLE, "severity": "high"})
sizes[name] = out["html_bytes"]
print(json.dumps({"ok": True, "templates": sizes}))
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
main()
print(json.dumps({"ok": True, "templates": TEMPLATES}))