notices: tell a human about what is NEW, and only when a notice actually went out
ci/woodpecker/push/woodpecker Pipeline was successful

Three fixes to the 'email only when there is a problem' rule, found by testing it:

1. The marker recorded the CURRENT set, so a set that SHRANK looked changed — one
   purchase granted dropped out, the remaining hold looked new, and it was mailed
   about twice. What a human has been TOLD is now a growing SET of keys
   (order:grant / order:hold, slug:class for backers): only keys not in it are
   mailed, and the union is stored.
2. A notify=False run advanced the marker, so a verification look CONSUMED the
   only alert a finding gets. The marker now advances only when the notice was
   actually sent (a failed send retries next sweep), and a clean pass clears it so
   a recurrence is news again.
3. The credit reconcile had the same shape of bug.

Tests updated to pin the new semantics: a smaller set re-mails nobody, a silent
look does not swallow the alert, a clean run clears the marker and a recurrence
speaks. 26 + 40 checks in those suites; all 19 suites green.
This commit is contained in:
inference-admin committed 2026-11-13 20:34:24 +00:00
1 parent f258a22aa3
commit 13b6131652
3 files changed
+127 -63

No files matched your search

+15 -7
View File
@@ -157,8 +157,8 @@ async def main():
check(f"info@ is told once, with every class in the body (got {len(SENT)})",
len(SENT) == 1 and SENT[0]["to"] == "info@inference.coop"
and "org-link" in SENT[0]["body"] and "out-of-band" in SENT[0]["body"])
check("it says it is sent on change, not every sweep",
"not on every sweep" in SENT[0]["body"])
check("it says the notice covers what is new, not every sweep",
"not every sweep" in SENT[0]["body"])
# Same set again: a report, but NO second email.
res2 = await m.reconcile_unmapped_backers()
@@ -169,14 +169,18 @@ async def main():
NODES[:] = [n for n in NODES
if ((n.get("account") or {}) or {}).get("slug") != "han"]
res3 = await m.reconcile_unmapped_backers()
check(f"a CHANGED set is reported again (got {res3.get('findings')} findings, {len(SENT)} emails)",
res3.get("findings") == 3 and len(SENT) == 2)
# A set that SHRINKS (one finding resolved) must NOT re-mail the survivors: a
# person already told about a finding is not told again just because the list
# got shorter. Only genuinely NEW keys speak.
check(f"a smaller set re-mails nobody (got {res3.get('findings')} findings, "
f"{res3.get('new')} new, {len(SENT)} emails)",
res3.get("findings") == 3 and res3.get("new") == 0 and len(SENT) == 1)
# Fully clear: silent, and the marker is cleared so a recurrence speaks up.
NODES[:] = [node("BACKER", "Membership", "alice", "alice@x.org", name="Alice")]
res4 = await m.reconcile_unmapped_backers()
check(f"a clean run says nothing (got {res4.get('findings')}, {len(SENT)} emails)",
res4.get("findings") == 0 and res4.get("reported") is False and len(SENT) == 2)
res4.get("findings") == 0 and res4.get("reported") is False and len(SENT) == 1)
conn = m.get_db()
marker = conn.execute("SELECT value FROM portal_state WHERE key = ?",
(m.UNMAPPED_BACKERS_MARKER,)).fetchone()
@@ -186,13 +190,17 @@ async def main():
NODES[:] = [node("BACKER", "Membership", "vic", "vic@x.org", name="Visible Vic")]
res5 = await m.reconcile_unmapped_backers()
check(f"a finding after a clean run speaks up again (got {len(SENT)} emails)",
res5.get("findings") == 1 and len(SENT) == 3)
res5.get("findings") == 1 and res5.get("new") == 1 and len(SENT) == 2)
# Notify can be suppressed (on-demand checks must not mail).
NODES[:] = [node("BACKER", "Membership", "newguy", "new@x.org", name="New Guy")]
res6 = await m.reconcile_unmapped_backers(notify=False)
check(f"notify=False suppresses the mail (got {res6.get('findings')} findings, {len(SENT)} emails)",
res6.get("findings") == 1 and res6.get("reported") is False and len(SENT) == 3)
res6.get("findings") == 1 and res6.get("reported") is False and len(SENT) == 2)
# ...and a look must not CONSUME the alert: the next notifying run still speaks.
res6b = await m.reconcile_unmapped_backers()
check(f"a silent look does not swallow the alert (got {res6b.get('new')} new, {len(SENT)} emails)",
res6b.get("reported") is True and len(SENT) == 3)
# A failed read is UNKNOWN, not silence.
FAIL_NODES = True