notices: tell a human about what is NEW, and only when a notice actually went out
ci/woodpecker/push/woodpecker Pipeline was successful
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:
1 parent
f258a22aa3
commit
13b6131652
3 files changed
+127
-63
No files matched your search
@@ -110,6 +110,11 @@ async def fake_index():
|
||||
|
||||
|
||||
BUDGET_PUSHES = []
|
||||
SENT = []
|
||||
|
||||
|
||||
def fake_send(to, subject, body, *a, **k):
|
||||
SENT.append({"to": to, "subject": subject, "body": body})
|
||||
|
||||
|
||||
async def fake_budget(email):
|
||||
@@ -145,6 +150,9 @@ def seed():
|
||||
conn.execute("DELETE FROM members")
|
||||
conn.execute("DELETE FROM credit_ledger")
|
||||
conn.execute("DELETE FROM held_credits")
|
||||
# A fresh world: the report markers are part of the state under test, so a
|
||||
# leftover fingerprint from an earlier section would silence a real notice.
|
||||
conn.execute("DELETE FROM portal_state")
|
||||
for email, slug, active in (("alice@x.org", "alice", 1), ("bob@x.org", "bob", 1),
|
||||
("carol@x.org", "carol", 1), ("dave@x.org", "dave", 0),
|
||||
("erin@x.org", "erin", 1), ("frank@x.org", "frank", 1)):
|
||||
@@ -179,6 +187,7 @@ async def main():
|
||||
m.fetch_collective_orders = fake_orders
|
||||
m.fetch_member_index = fake_index
|
||||
m.sync_team_budget_from_balance = fake_budget
|
||||
m.send_email = fake_send
|
||||
|
||||
# ---------- dry run: report only, change nothing --------------------------
|
||||
seed()
|
||||
@@ -248,6 +257,7 @@ async def main():
|
||||
|
||||
# ---------- CREDIT_RECONCILE=on: grant exactly once ----------------------
|
||||
seed()
|
||||
SENT.clear()
|
||||
m.CREDIT_RECONCILE = "on"
|
||||
res = await m.reconcile_credit_packs(apply=True)
|
||||
check(f"apply grants the one candidate (got {res.get('applied')})",
|
||||
@@ -265,6 +275,12 @@ async def main():
|
||||
check("the out-of-window member was NOT credited",
|
||||
balance("frank@x.org") == 0.0)
|
||||
|
||||
# The money notice: someone is told when a purchase had to be recovered —
|
||||
# and NOT told again about a set they have already heard about.
|
||||
check(f"the grant mails a notice naming the order (got {len(SENT)})",
|
||||
len(SENT) == 1 and "or_CCC" in SENT[0]["body"] and "carol" in SENT[0]["body"]
|
||||
and SENT[0]["to"] == "info@inference.coop")
|
||||
|
||||
# the webhook and this pass must dedupe each other, whichever runs first
|
||||
check("the webhook would now answer already_credited for this order",
|
||||
m.credit_reference_exists(m.credit_pack_reference("carol", {"idV2": "or_CCC"})))
|
||||
@@ -276,6 +292,7 @@ async def main():
|
||||
balance("carol@x.org") == 10.0)
|
||||
check(f"still one row for the order (got {len(ledger_rows())})",
|
||||
len(ledger_rows()) == 4)
|
||||
check(f"a re-run with nothing to report mails nothing (got {len(SENT)})", len(SENT) == 1)
|
||||
|
||||
# ---------- a candidate must SHOW the nearby rows a human needs ----------
|
||||
# A manual grant can be real and carry no per-order reference: ntnsndr's three
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user