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
|
||||
|
||||
Reference in new issue
Block a user