fix(projekt-matching): verify teamsIds/account equality in read-back; always post trace
This commit is contained in:
@@ -133,9 +133,11 @@ def stage_crm(ctx, cfg, espo=None):
|
|||||||
problems.append("cProjektlink")
|
problems.append("cProjektlink")
|
||||||
if back.get("description") != ctx["description"]:
|
if back.get("description") != ctx["description"]:
|
||||||
problems.append("description")
|
problems.append("description")
|
||||||
if account_id and agency and not back.get("cAccount1Id"):
|
if team not in (back.get("teamsIds") or []):
|
||||||
|
problems.append("teamsIds")
|
||||||
|
if account_id and agency and back.get("cAccount1Id") != account_id:
|
||||||
problems.append("cAccount1Id")
|
problems.append("cAccount1Id")
|
||||||
if account_id and not agency and not back.get("accountId"):
|
if account_id and not agency and back.get("accountId") != account_id:
|
||||||
problems.append("accountId")
|
problems.append("accountId")
|
||||||
if problems:
|
if problems:
|
||||||
raise RuntimeError(f"CRM-Verifikation fehlgeschlagen: {problems}")
|
raise RuntimeError(f"CRM-Verifikation fehlgeschlagen: {problems}")
|
||||||
@@ -145,6 +147,11 @@ def stage_crm(ctx, cfg, espo=None):
|
|||||||
|
|
||||||
|
|
||||||
def stage_notify(ctx, cfg):
|
def stage_notify(ctx, cfg):
|
||||||
|
"""Send notification on created; ALWAYS post the Langfuse trace.
|
||||||
|
|
||||||
|
Called directly by the component (not via run_stage), so failed runs
|
||||||
|
still get their trace and an SMTP error cannot lose it."""
|
||||||
|
try:
|
||||||
if ctx.get("status") == "created":
|
if ctx.get("status") == "created":
|
||||||
subject = (f"[Projekt-Match] Freelancermap — {ctx['mustMatch']} % — "
|
subject = (f"[Projekt-Match] Freelancermap — {ctx['mustMatch']} % — "
|
||||||
f"{ctx['projectName']}")
|
f"{ctx['projectName']}")
|
||||||
@@ -155,6 +162,8 @@ def stage_notify(ctx, cfg):
|
|||||||
f"CRM-Verkaufschance: {ctx['crmUrl']}\n")
|
f"CRM-Verkaufschance: {ctx['crmUrl']}\n")
|
||||||
mailer.send_mail(cfg.imap_user, cfg.imap_password, cfg.notify_to,
|
mailer.send_mail(cfg.imap_user, cfg.imap_password, cfg.notify_to,
|
||||||
subject, body)
|
subject, body)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
ctx.update(status="failed", error=f"notify: {exc}")
|
||||||
pm_trace.post_trace(ctx)
|
pm_trace.post_trace(ctx)
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|||||||
@@ -100,3 +100,10 @@ def test_stage_notify_only_on_created():
|
|||||||
sent.clear()
|
sent.clear()
|
||||||
stages.stage_notify({"status": "rejected"}, CFG)
|
stages.stage_notify({"status": "rejected"}, CFG)
|
||||||
assert not sent
|
assert not sent
|
||||||
|
traced = []
|
||||||
|
with mock.patch("projektmatch.stages.mailer.send_mail",
|
||||||
|
lambda *a: sent.append(a)), \
|
||||||
|
mock.patch("projektmatch.stages.pm_trace.post_trace",
|
||||||
|
lambda c: traced.append(c["status"])):
|
||||||
|
stages.stage_notify({"status": "failed", "error": "x"}, CFG)
|
||||||
|
assert traced == ["failed"] and not sent
|
||||||
|
|||||||
Reference in New Issue
Block a user