Guest cap $5 -> $2: GUEST_BUDGET default, emails, docs, tests

This commit is contained in:
inference-bot committed 2026-11-08 20:12:47 +00:00
1 parent 0f12c63f5e
commit 6be8e2d632
6 files changed
+45 -45

No files matched your search

+9 -9
View File
@@ -112,7 +112,7 @@ m.listmonk_sync = rec_listmonk
m.send_email = rec_email
def seed_gift(conn, email, active=1, credits=5.0, balance=0.0):
def seed_gift(conn, email, active=1, credits=2.0, balance=0.0):
conn.execute(
"INSERT INTO members (email, key_token, cloudron_user_id, slug, active, "
"balance, credit_balance, account_type, guest_expires_at) "
@@ -160,11 +160,11 @@ def main():
# --- 3-8. the full cancel flow ------------------------------------------
conn = m.get_db()
seed_gift(conn, "invited@x.org", active=1, credits=5.0)
seed_gift(conn, "invited@x.org", active=1, credits=2.0)
# the grant row production writes at provisioning (add_credits on the
# guest reference) — the return is audited against it
conn.execute("INSERT INTO credit_ledger (email, delta, reason, reference) "
"VALUES ('invited@x.org', 5.0, 'guest account — $5 credit from a member', "
"VALUES ('invited@x.org', 2.0, 'guest account — $2 credit from a member', "
"'guest:invited@x.org')")
conn.commit()
conn.close()
@@ -186,9 +186,9 @@ def main():
led = ledger_rows(conn, "invited@x.org")
grants = [r for r in led if r[2] == "guest:invited@x.org"]
returns = [r for r in led if r[2] == "guest-return:invited@x.org"]
check("cancel: ledger holds the $5 grant and ONE negative return row",
len(grants) == 1 and grants[0][0] == 5.0 and len(returns) == 1
and returns[0][0] == -5.0, str(led))
check("cancel: ledger holds the $2 grant and ONE negative return row",
len(grants) == 1 and grants[0][0] == 2.0 and len(returns) == 1
and returns[0][0] == -2.0, str(led))
check("cancel: return reason names the cancellation and the guest reference",
len(returns) == 1 and "cancelled by recipient" in returns[0][1]
and "guest:invited@x.org" in returns[0][1], str(returns))
@@ -198,7 +198,7 @@ def main():
g and g[0] == "member-one@x.org" and g[1] == "invited@x.org"
and g[2] == "cancelled by recipient", str(g))
check("cancel: result reports the returned amount",
out.get("status") == "cancelled" and out.get("credits_returned") == 5.0, str(out))
out.get("status") == "cancelled" and out.get("credits_returned") == 2.0, str(out))
conn.close()
# --- 9. idempotence: the second cancel is a no-op -----------------------
@@ -260,11 +260,11 @@ def main():
}
check("status: cancelled guest reads ended + cancelled + amount returned",
st_cancelled["ended"] and st_cancelled["cancelled"]
and st_cancelled["credits_returned"] == 5.0, str(st_cancelled))
and st_cancelled["credits_returned"] == 2.0, str(st_cancelled))
# live guest: active with remaining credits
conn = m.get_db()
seed_gift(conn, "live@x.org", active=1, credits=5.0)
seed_gift(conn, "live@x.org", active=1, credits=2.0)
conn.commit()
conn.close()
st_live = {
+7 -7
View File
@@ -2,7 +2,7 @@
"""Guest-account lifecycle tests — structurally isolated from live services.
WHY THIS EXISTS
Guest accounts (operator feature, 2026-11-08) touch money ($5 of credits),
Guest accounts (operator feature, 2026-11-08) touch money ($2 of credits),
Cloudron groups and email. Every path proven here runs against a FIXTURE
database with the network layer REPLACED BY A RAISING GUARD: any code path
that tries to reach Cloudron, LiteLLM, OC, Listmonk, Loomio, Matrix or SMTP
@@ -237,12 +237,12 @@ def main():
conn = m.get_db()
check("provision: row marked guest", row_of(conn, "invited@x.org", "account_type") == "guest")
check("provision: allowance balance 0", row_of(conn, "invited@x.org", "balance") == 0.0)
check("provision: $5 credit", row_of(conn, "invited@x.org", "credit_balance") == 5.0)
check("provision: $2 credit", row_of(conn, "invited@x.org", "credit_balance") == 2.0)
check("provision: guest_expires_at set", bool(row_of(conn, "invited@x.org", "guest_expires_at")))
check("provision: group = guests group",
calls["group"] and calls["group"][0][1] == m.GUESTS_GROUP_ID, str(calls["group"]))
check("provision: cap set to 5.00 (one-time)",
(calls["budget"] and calls["budget"][0][1] == 5.0), str(calls["budget"]))
check("provision: cap set to 2.00 (one-time)",
(calls["budget"] and calls["budget"][0][1] == 2.0), str(calls["budget"]))
check("provision: invitation email sent (merged invite + welcome)",
any("invited to the Inference Cooperative" in s for _, s in calls["email"]), str(calls["email"]))
check("provision: newsletter subscribed",
@@ -264,11 +264,11 @@ def main():
check("convert: allowance lifted to MEMBER_BUDGET",
row_of(conn, "invited@x.org", "balance") == m.MEMBER_BUDGET)
check("convert: unspent guest credit carried",
row_of(conn, "invited@x.org", "credit_balance") == 5.0)
row_of(conn, "invited@x.org", "credit_balance") == 2.0)
check("convert: group moved to members",
calls["group"] and calls["group"][0][1] == m.MEMBERS_GROUP_ID, str(calls["group"]))
check("convert: cap lifted to 20.00 (15 + 5 credits)",
(calls["budget"] and calls["budget"][0][1] == m.MEMBER_BUDGET + 5.0), str(calls["budget"]))
check("convert: cap lifted to 17.00 (15 + 2 credits)",
(calls["budget"] and calls["budget"][0][1] == m.MEMBER_BUDGET + 2.0), str(calls["budget"]))
check("convert: anchor day kept", row_of(conn, "invited@x.org", "anchor_day") == anchor_before)
check("convert: congrats email sent",
any("member now" in s for _, s in calls["email"]), str(calls["email"]))
+3 -3
View File
@@ -2,7 +2,7 @@
"""Member self-serve guest requests — structurally isolated from live services.
WHY THIS EXISTS
The member path creates REAL guest accounts ($5 of credits, Cloudron users,
The member path creates REAL guest accounts ($2 of credits, Cloudron users,
invitation email) once approved, and the trial gate decides when. Every path
proven here runs against a FIXTURE database with the network layer REPLACED
BY A RAISING GUARD: any code path that tries to reach Cloudron, LiteLLM, OC,
@@ -25,7 +25,7 @@ WHY THIS EXISTS
members invite guests.
APPROVAL (the panel action)
9. Approve fires the FULL guest pipeline: row marked account_type='guest',
$5 credit, ledger row inviter → recipient, the invitation email (the
$2 credit, ledger row inviter → recipient, the invitation email (the
INVITING member named in it), newsletter subscribe — and the request
row becomes 'approved'.
10. Approving a request whose guard now refuses (state moved) records the
@@ -306,7 +306,7 @@ def main():
"SELECT account_type, balance, credit_balance FROM members WHERE email = ?",
("friend@x.org",)).fetchone()
check("approve: recipient row marked guest", acct and acct[0] == "guest", str(acct))
check("approve: $5 non-expiring credit", acct and acct[2] == 5.0, str(acct))
check("approve: $2 non-expiring credit", acct and acct[2] == 2.0, str(acct))
ledger = conn.execute(
"SELECT inviter_email, recipient_email, status FROM guests WHERE recipient_email = 'friend@x.org'"
).fetchall()