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

+3 -3
View File
@@ -50,7 +50,7 @@ LibreChat ──→ Member Portal ──→ LiteLLM ──→ backend
| `ALLOWANCE_POLICY` | `report` (default) \| `on`. `report` computes every allowance decision and changes nothing; `on` performs renewals and sends the one reminder. Deactivation is gated separately by `ALLOWANCE_DEACTIVATE`. | | `ALLOWANCE_POLICY` | `report` (default) \| `on`. `report` computes every allowance decision and changes nothing; `on` performs renewals and sends the one reminder. Deactivation is gated separately by `ALLOWANCE_DEACTIVATE`. |
| `ALLOWANCE_DEACTIVATE` | `off` (default) \| `on`. When `on`, a member who was reminded and is still unpaid after the grace window is moved to the inactive group. **Defaults off so renewals/reminders can run before anyone loses access.** | | `ALLOWANCE_DEACTIVATE` | `off` (default) \| `on`. When `on`, a member who was reminded and is still unpaid after the grace window is moved to the inactive group. **Defaults off so renewals/reminders can run before anyone loses access.** |
| `PAYMENT_GRACE_DAYS` | Days after the single reminder before an unpaid member is deactivated (default `7`). | | `PAYMENT_GRACE_DAYS` | Days after the single reminder before an unpaid member is deactivated (default `7`). |
| `GUEST_BUDGET` | Guest-account credit in USD (default `5.0`). | | `GUEST_BUDGET` | Guest-account credit in USD (default `2.0`). |
| `GUEST_DAYS` | Guest-account time box in days from provisioning (default `60`). The sweep deactivates an expired guest even with credits left. | | `GUEST_DAYS` | Guest-account time box in days from provisioning (default `60`). The sweep deactivates an expired guest even with credits left. |
| `GUEST_PER_INVITER_DAYS` | Rolling window for the one-guest-per-inviter limit (default `30`). | | `GUEST_PER_INVITER_DAYS` | Rolling window for the one-guest-per-inviter limit (default `30`). |
| `GUESTS_GROUP_ID` | Cloudron group ID for guest accounts. The chat and dashboard apps' access restrictions list BOTH the members and guests groups, so a guest reaches exactly those two apps. | | `GUESTS_GROUP_ID` | Cloudron group ID for guest accounts. The chat and dashboard apps' access restrictions list BOTH the members and guests groups, so a guest reaches exactly those two apps. |
@@ -58,12 +58,12 @@ LibreChat ──→ Member Portal ──→ LiteLLM ──→ backend
## Guest accounts ## Guest accounts
A member can give a friend access to the co-op with $5 of credits — no Open A member can give a friend access to the co-op with $2 of credits — no Open
Collective membership required. `POST /admin/provision-guest` (X-Admin-Token) Collective membership required. `POST /admin/provision-guest` (X-Admin-Token)
with `{"email", "name", "inviter": "<the guest access member's email>"}` runs the with `{"email", "name", "inviter": "<the guest access member's email>"}` runs the
guest pipeline: Cloudron user in the **guests** group, a LiteLLM team capped at guest pipeline: Cloudron user in the **guests** group, a LiteLLM team capped at
`GUEST_BUDGET` with **no monthly reset** (the cap is the guest's whole life), the `GUEST_BUDGET` with **no monthly reset** (the cap is the guest's whole life), the
portal row marked `account_type='guest'` with the $5 held as non-expiring portal row marked `account_type='guest'` with the $2 held as non-expiring
credit, `guest_expires_at` set to now + `GUEST_DAYS`, the guest welcome email credit, `guest_expires_at` set to now + `GUEST_DAYS`, the guest welcome email
(setup link, what they can use, Become-a-member, newsletter note), and a (setup link, what they can use, Become-a-member, newsletter note), and a
**guests ledger** row (`guests` table: inviter → recipient, expiry, status) for **guests ledger** row (`guests` table: inviter → recipient, expiry, status) for
+22 -22
View File
@@ -336,18 +336,18 @@ OC_PERSONAL_TOKEN = os.environ.get("OC_PERSONAL_TOKEN", "")
MEMBER_BUDGET = float(os.environ.get("MEMBER_BUDGET", "15.0")) MEMBER_BUDGET = float(os.environ.get("MEMBER_BUDGET", "15.0"))
# --- Guest accounts (operator decisions, 2026-11-08) -------------------------- # # --- Guest accounts (operator decisions, 2026-11-08) -------------------------- #
# A member can give a friend access to the co-op with $5 of credits, no Open # A member can give a friend access to the co-op with $2 of credits, no Open
# Collective membership required. The guest is a ONE-TIME non-expiring credit # Collective membership required. The guest is a ONE-TIME non-expiring credit
# balance held in the credits model (credit_balance), hard-capped by the # balance held in the credits model (credit_balance), hard-capped by the
# LiteLLM team budget. Two lapse triggers, both handled by the sweep: # LiteLLM team budget. Two lapse triggers, both handled by the sweep:
# * the $5 is spent (the cap enforces the limit; the sweep deactivates the # * the $2 is spent (the cap enforces the limit; the sweep deactivates the
# row once spend reaches the credit balance), and # row once spend reaches the credit balance), and
# * GUEST_DAYS elapse from provisioning — a time box, even with credits left. # * GUEST_DAYS elapse from provisioning — a time box, even with credits left.
# Deactivation is the same semantics as a member's: guests group → inactive, # Deactivation is the same semantics as a member's: guests group → inactive,
# team budget zeroed, row active=0, newsletter unsubscribed. The account is # team budget zeroed, row active=0, newsletter unsubscribed. The account is
# KEPT so a returning payer resumes cleanly (and the guest→member conversion # KEPT so a returning payer resumes cleanly (and the guest→member conversion
# still fires if their OC membership appears later). # still fires if their OC membership appears later).
GUEST_BUDGET = float(os.environ.get("GUEST_BUDGET", "5.0")) GUEST_BUDGET = float(os.environ.get("GUEST_BUDGET", "2.0"))
GUEST_DAYS = float(os.environ.get("GUEST_DAYS", "60")) GUEST_DAYS = float(os.environ.get("GUEST_DAYS", "60"))
# One guest per inviting member per rolling 30 days (abuse protection). # One guest per inviting member per rolling 30 days (abuse protection).
GUEST_PER_INVITER_DAYS = float(os.environ.get("GUEST_PER_INVITER_DAYS", "30")) GUEST_PER_INVITER_DAYS = float(os.environ.get("GUEST_PER_INVITER_DAYS", "30"))
@@ -923,7 +923,7 @@ def get_db() -> sqlite3.Connection:
if "loomio_invited_at" not in cols: if "loomio_invited_at" not in cols:
conn.execute("ALTER TABLE members ADD COLUMN loomio_invited_at TEXT") conn.execute("ALTER TABLE members ADD COLUMN loomio_invited_at TEXT")
# Migration: account_type — 'member' (default) or 'guest'. Guest accounts are # Migration: account_type — 'member' (default) or 'guest'. Guest accounts are
# provisioned by /admin/provision-guest with $5 of non-expiring credit, live # provisioned by /admin/provision-guest with $2 of non-expiring credit, live
# in the Cloudron "guests" group, and sit outside every membership # in the Cloudron "guests" group, and sit outside every membership
# obligation: the sweep never deactivates one for lacking an OC # obligation: the sweep never deactivates one for lacking an OC
# contribution, they are invited to no Loomio/Matrix rooms, and they lapse # contribution, they are invited to no Loomio/Matrix rooms, and they lapse
@@ -1579,7 +1579,7 @@ async def get_active_member_emails() -> list[str]:
The local `members` table is the authoritative source of member emails The local `members` table is the authoritative source of member emails
(populated during provisioning). Used for the Loomio sync and the Matrix (populated during provisioning). Used for the Loomio sync and the Matrix
invite pass. GUEST accounts are excluded: they are not members — they hold invite pass. GUEST accounts are excluded: they are not members — they hold
$5 credits, live in the Cloudron guests group, and must never be invited $2 credits, live in the Cloudron guests group, and must never be invited
to Loomio, Matrix or (via these lists) any member service. to Loomio, Matrix or (via these lists) any member service.
""" """
conn = get_db() conn = get_db()
@@ -2529,7 +2529,7 @@ async def provision_member(email: str, name: str, slug: str = "") -> str:
# --- Guest accounts (operator feature, 2026-11-08) --------------------------- # # --- Guest accounts (operator feature, 2026-11-08) --------------------------- #
# A member gives a friend access with $5 of credits: Cloudron user in the # A member gives a friend access with $2 of credits: Cloudron user in the
# guests group (chat + dashboard only), a one-time LiteLLM budget with NO # guests group (chat + dashboard only), a one-time LiteLLM budget with NO
# monthly reset, the portal row marked account_type='guest', the guest welcome # monthly reset, the portal row marked account_type='guest', the guest welcome
# email, and the newsletter subscription. NO Loomio/Matrix invites. See the # email, and the newsletter subscription. NO Loomio/Matrix invites. See the
@@ -2539,7 +2539,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
"""Build the guest INVITATION email — the one email a guest sends. """Build the guest INVITATION email — the one email a guest sends.
This is the guest-time email AND the guest welcome in one: the recipient is This is the guest-time email AND the guest welcome in one: the recipient is
invited in (the inviter named), told what the guest gives ($5 of credits, invited in (the inviter named), told what the guest gives ($2 of credits,
how long access runs), and given the account-setup link. The guest welcome how long access runs), and given the account-setup link. The guest welcome
content lives here rather than in a second email — one coherent invitation, content lives here rather than in a second email — one coherent invitation,
not two mails at once. Same branded shell as welcome_email(): cream not two mails at once. Same branded shell as welcome_email(): cream
@@ -2565,7 +2565,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
f"{greet}\n\n" f"{greet}\n\n"
f"{invited_line}.\n\n" f"{invited_line}.\n\n"
"It's a member-governed AI cooperative that runs open models.\n\n" "It's a member-governed AI cooperative that runs open models.\n\n"
"Your invitation comes with $5 of credits for the co-op's chat and\n" "Your invitation comes with $2 of credits for the co-op's chat and\n"
f"API. Access runs for {int(GUEST_DAYS)} days from today; the credits\n" f"API. Access runs for {int(GUEST_DAYS)} days from today; the credits\n"
"themselves don't expire early.\n\n" "themselves don't expire early.\n\n"
"To accept, create your account — it takes about a minute:\n\n" "To accept, create your account — it takes about a minute:\n\n"
@@ -2596,7 +2596,7 @@ def guest_invitation_email(name: str, setup_url: str, inviter_name: str = "") ->
<td align="center" style="background:#ffffff;border:1px solid #e8e2d8;border-radius:16px;padding:40px 32px;"> <td align="center" style="background:#ffffff;border:1px solid #e8e2d8;border-radius:16px;padding:40px 32px;">
<h1 style="margin:0 0 12px;font-size:24px;font-weight:700;color:#2d3327;">{h1}</h1> <h1 style="margin:0 0 12px;font-size:24px;font-weight:700;color:#2d3327;">{h1}</h1>
<p style="margin:0 0 8px;font-size:16px;color:#6b7a62;line-height:1.5;">{html_invited} — a member-governed AI cooperative running open models.</p> <p style="margin:0 0 8px;font-size:16px;color:#6b7a62;line-height:1.5;">{html_invited} — a member-governed AI cooperative running open models.</p>
<p style="margin:0 0 24px;font-size:15px;color:#6b7a62;line-height:1.5;">Your invitation comes with <strong style="color:#2d3327;">$5 of credits</strong> for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.</p> <p style="margin:0 0 24px;font-size:15px;color:#6b7a62;line-height:1.5;">Your invitation comes with <strong style="color:#2d3327;">$2 of credits</strong> for the co-op's chat and API. Access runs for {int(GUEST_DAYS)} days from today; the credits themselves don't expire early.</p>
<a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Create your account</a> <a href="{setup_url}" style="display:inline-block;background:#5b8c5a;color:#ffffff;text-decoration:none;padding:14px 36px;border-radius:10px;font-size:16px;font-weight:600;">Create your account</a>
<p style="margin:14px 0 28px;font-size:13px;color:#94a08c;line-height:1.5;">This takes about a minute.</p> <p style="margin:14px 0 28px;font-size:13px;color:#94a08c;line-height:1.5;">This takes about a minute.</p>
<p style="margin:0 0 10px;font-size:15px;color:#2d3327;line-height:1.5;"><strong>If you like it, become a member.</strong></p> <p style="margin:0 0 10px;font-size:15px;color:#2d3327;line-height:1.5;"><strong>If you like it, become a member.</strong></p>
@@ -2675,7 +2675,7 @@ def guest_member_congrats_email(name: str, setup_url: str | None) -> tuple[str,
def guest_limits_email(name: str, reason: str) -> tuple[str, str, str]: def guest_limits_email(name: str, reason: str) -> tuple[str, str, str]:
"""Build the reaching-limits email for a guest account hitting its limit. """Build the reaching-limits email for a guest account hitting its limit.
Sent ONCE per guest when the sweep deactivates the guest — either the $5 Sent ONCE per guest when the sweep deactivates the guest — either the $2
of credits are spent or the GUEST_DAYS time box has run out. Says plainly: of credits are spent or the GUEST_DAYS time box has run out. Says plainly:
the guest access has ended, the account and data are kept, and becoming a the guest access has ended, the account and data are kept, and becoming a
member ($15/month via Open Collective) restores access with a full member ($15/month via Open Collective) restores access with a full
@@ -2734,14 +2734,14 @@ async def provision_guest_member(
) -> str: ) -> str:
"""Provision a GUEST account end-to-end (operator guest access feature). """Provision a GUEST account end-to-end (operator guest access feature).
A guest gives a friend $5 of credits with no Open Collective membership: A guest gives a friend $2 of credits with no Open Collective membership:
* Cloudron user in the GUESTS group (chat + dashboard only — the two * Cloudron user in the GUESTS group (chat + dashboard only — the two
apps' access restrictions list both groups); apps' access restrictions list both groups);
* a LiteLLM team hard-capped at GUEST_BUDGET with NO monthly reset * a LiteLLM team hard-capped at GUEST_BUDGET with NO monthly reset
(budget_duration None — the cap is the guest's whole life); (budget_duration None — the cap is the guest's whole life);
* the portal row marked account_type='guest' with the $5 held as * the portal row marked account_type='guest' with the $2 held as
non-expiring credit (the credits model) and guest_expires_at set; non-expiring credit (the credits model) and guest_expires_at set;
* the guest INVITATION email (inviter named, the $5 credits, the * the guest INVITATION email (inviter named, the $2 credits, the
setup link — the invitation and the guest welcome in one) and the setup link — the invitation and the guest welcome in one) and the
newsletter subscription; newsletter subscription;
* a guests-ledger row recording inviter → recipient; * a guests-ledger row recording inviter → recipient;
@@ -2768,7 +2768,7 @@ async def provision_guest_member(
await cloudron_set_group(user_id, GUESTS_GROUP_ID) await cloudron_set_group(user_id, GUESTS_GROUP_ID)
await cloudron_set_active(user_id, True) await cloudron_set_active(user_id, True)
# One-time $5 team: budget_duration None means LiteLLM never resets it. # One-time $2 team: budget_duration None means LiteLLM never resets it.
team_id = await litellm_get_or_create_team(email, GUEST_BUDGET, budget_duration=None) team_id = await litellm_get_or_create_team(email, GUEST_BUDGET, budget_duration=None)
key_token = get_stored_key(email) key_token = get_stored_key(email)
if not key_token: if not key_token:
@@ -2781,9 +2781,9 @@ async def provision_guest_member(
guest_ref = f"guest:{email}" guest_ref = f"guest:{email}"
if not credit_reference_exists(guest_ref): if not credit_reference_exists(guest_ref):
add_credits(email, GUEST_BUDGET, add_credits(email, GUEST_BUDGET,
reason="guest account — $5 credit from a member", reason="guest account — $2 credit from a member",
reference=guest_ref) reference=guest_ref)
# Guest rows hold NO allowance (balance 0 — the $5 is all credit) and # Guest rows hold NO allowance (balance 0 — the $2 is all credit) and
# anchor their join day at the guest date (kept if they later convert). # anchor their join day at the guest date (kept if they later convert).
conn = get_db() conn = get_db()
conn.execute( conn.execute(
@@ -2849,7 +2849,7 @@ async def convert_guest_to_member(email: str, name: str, slug: str = "") -> str:
What converts: What converts:
* the Cloudron user moves guests → members (regaining Loomio/Matrix * the Cloudron user moves guests → members (regaining Loomio/Matrix
eligibility through the normal syncs); eligibility through the normal syncs);
* the LiteLLM cap lifts from the $5 guest to the member allowance + * the LiteLLM cap lifts from the $2 guest to the member allowance +
credits — any UNSPENT guest credit stays (it already lives in the credits — any UNSPENT guest credit stays (it already lives in the
non-expiring credit_balance bucket); non-expiring credit_balance bucket);
* the portal row becomes account_type='member' with the standard * the portal row becomes account_type='member' with the standard
@@ -3279,7 +3279,7 @@ async def litellm_get_or_create_team(email: str, budget: float,
spend draws from the one pool. spend draws from the one pool.
`budget_duration` is the reset cadence: members renew every 30 days; GUEST `budget_duration` is the reset cadence: members renew every 30 days; GUEST
accounts pass None — a one-time budget that NEVER resets, so the $5 cap is accounts pass None — a one-time budget that NEVER resets, so the $2 cap is
the guest's whole life (spend it and it is gone). the guest's whole life (spend it and it is gone).
Idempotent: looks up the existing team by alias before creating. Note that Idempotent: looks up the existing team by alias before creating. Note that
@@ -4221,7 +4221,7 @@ async def admin_provision_guest(request: Request):
(ADMIN_INVITER_EMAIL, default info@inference.coop) — the panel has no (ADMIN_INVITER_EMAIL, default info@inference.coop) — the panel has no
inviter input, and the ledger records the admin account. inviter input, and the ledger records the admin account.
Runs the guest pipeline: Cloudron user in the guests group, a $5 LiteLLM Runs the guest pipeline: Cloudron user in the guests group, a $2 LiteLLM
team with NO monthly reset, the portal row marked as a guest with a team with NO monthly reset, the portal row marked as a guest with a
GUEST_DAYS expiry, the guest welcome email, the newsletter subscription, GUEST_DAYS expiry, the guest welcome email, the newsletter subscription,
and a guests-ledger row recording inviter → recipient. Admin invites and a guests-ledger row recording inviter → recipient. Admin invites
@@ -4375,7 +4375,7 @@ async def admin_guest_request_approve(request_id: int, request: Request):
"""Approve a pending guest request — the trial gate's approval action. """Approve a pending guest request — the trial gate's approval action.
Approval fires the FULL guest pipeline (provision_guest_member: Cloudron Approval fires the FULL guest pipeline (provision_guest_member: Cloudron
user, $5 credit, GUEST_DAYS box, invitation email naming the inviter, user, $2 credit, GUEST_DAYS box, invitation email naming the inviter,
newsletter subscribe, ledger row) — the same path the operator's newsletter subscribe, ledger row) — the same path the operator's
/admin/provision-guest runs, so every guard re-runs. If state moved since /admin/provision-guest runs, so every guard re-runs. If state moved since
the request (the recipient signed up; another invitation landed), the the request (the recipient signed up; another invitation landed), the
@@ -6250,7 +6250,7 @@ async def broker_guest_invite(request: Request):
pending request, or a MANUAL_MEMBERS address. The guest itself is pending request, or a MANUAL_MEMBERS address. The guest itself is
provisioned ONLY through provision_guest_member — the same pipeline the provisioned ONLY through provision_guest_member — the same pipeline the
operator's /admin/provision-guest runs (Cloudron user in the guests operator's /admin/provision-guest runs (Cloudron user in the guests
group, $5 non-expiring credit, GUEST_DAYS time box, invitation email group, $2 non-expiring credit, GUEST_DAYS time box, invitation email
naming the inviter, newsletter subscribe, ledger row). naming the inviter, newsletter subscribe, ledger row).
Trial gate: with GUEST_AUTO_APPROVE off (the default) the request waits Trial gate: with GUEST_AUTO_APPROVE off (the default) the request waits
@@ -7047,7 +7047,7 @@ async def reconcile_allowances(send: bool = False) -> dict:
welcome_sent = row[6] if len(row) > 6 else None welcome_sent = row[6] if len(row) > 6 else None
if acct_type == "guest": if acct_type == "guest":
# Guest accounts have no OC membership by design — the $5 credit # Guest accounts have no OC membership by design — the $2 credit
# balance and the GUEST_DAYS time box govern them instead. No # balance and the GUEST_DAYS time box govern them instead. No
# renewal decision, no reminder, ever. # renewal decision, no reminder, ever.
counts["skipped"] += 1 counts["skipped"] += 1
+1 -1
View File
@@ -207,7 +207,7 @@ def from_sqlite() -> dict:
"""Members, plus the provisioning dates that give the growth curve. """Members, plus the provisioning dates that give the growth curve.
Operator/utility accounts are excluded, matching the panel's member count. Operator/utility accounts are excluded, matching the panel's member count.
GUEST accounts are excluded too: they are $5 guest passes, not members — GUEST accounts are excluded too: they are $2 guest passes, not members —
counting them would move the growth curve the co-op publishes. counting them would move the growth curve the co-op publishes.
""" """
conn = connect() conn = connect()
+9 -9
View File
@@ -112,7 +112,7 @@ m.listmonk_sync = rec_listmonk
m.send_email = rec_email 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( conn.execute(
"INSERT INTO members (email, key_token, cloudron_user_id, slug, active, " "INSERT INTO members (email, key_token, cloudron_user_id, slug, active, "
"balance, credit_balance, account_type, guest_expires_at) " "balance, credit_balance, account_type, guest_expires_at) "
@@ -160,11 +160,11 @@ def main():
# --- 3-8. the full cancel flow ------------------------------------------ # --- 3-8. the full cancel flow ------------------------------------------
conn = m.get_db() 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 # the grant row production writes at provisioning (add_credits on the
# guest reference) — the return is audited against it # guest reference) — the return is audited against it
conn.execute("INSERT INTO credit_ledger (email, delta, reason, reference) " 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')") "'guest:invited@x.org')")
conn.commit() conn.commit()
conn.close() conn.close()
@@ -186,9 +186,9 @@ def main():
led = ledger_rows(conn, "invited@x.org") led = ledger_rows(conn, "invited@x.org")
grants = [r for r in led if r[2] == "guest: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"] 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", check("cancel: ledger holds the $2 grant and ONE negative return row",
len(grants) == 1 and grants[0][0] == 5.0 and len(returns) == 1 len(grants) == 1 and grants[0][0] == 2.0 and len(returns) == 1
and returns[0][0] == -5.0, str(led)) and returns[0][0] == -2.0, str(led))
check("cancel: return reason names the cancellation and the guest reference", check("cancel: return reason names the cancellation and the guest reference",
len(returns) == 1 and "cancelled by recipient" in returns[0][1] len(returns) == 1 and "cancelled by recipient" in returns[0][1]
and "guest:invited@x.org" in returns[0][1], str(returns)) 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" g and g[0] == "member-one@x.org" and g[1] == "invited@x.org"
and g[2] == "cancelled by recipient", str(g)) and g[2] == "cancelled by recipient", str(g))
check("cancel: result reports the returned amount", 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() conn.close()
# --- 9. idempotence: the second cancel is a no-op ----------------------- # --- 9. idempotence: the second cancel is a no-op -----------------------
@@ -260,11 +260,11 @@ def main():
} }
check("status: cancelled guest reads ended + cancelled + amount returned", check("status: cancelled guest reads ended + cancelled + amount returned",
st_cancelled["ended"] and st_cancelled["cancelled"] 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 # live guest: active with remaining credits
conn = m.get_db() 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.commit()
conn.close() conn.close()
st_live = { st_live = {
+7 -7
View File
@@ -2,7 +2,7 @@
"""Guest-account lifecycle tests — structurally isolated from live services. """Guest-account lifecycle tests — structurally isolated from live services.
WHY THIS EXISTS 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 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 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 that tries to reach Cloudron, LiteLLM, OC, Listmonk, Loomio, Matrix or SMTP
@@ -237,12 +237,12 @@ def main():
conn = m.get_db() conn = m.get_db()
check("provision: row marked guest", row_of(conn, "invited@x.org", "account_type") == "guest") 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: 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: guest_expires_at set", bool(row_of(conn, "invited@x.org", "guest_expires_at")))
check("provision: group = guests group", check("provision: group = guests group",
calls["group"] and calls["group"][0][1] == m.GUESTS_GROUP_ID, str(calls["group"])) calls["group"] and calls["group"][0][1] == m.GUESTS_GROUP_ID, str(calls["group"]))
check("provision: cap set to 5.00 (one-time)", check("provision: cap set to 2.00 (one-time)",
(calls["budget"] and calls["budget"][0][1] == 5.0), str(calls["budget"])) (calls["budget"] and calls["budget"][0][1] == 2.0), str(calls["budget"]))
check("provision: invitation email sent (merged invite + welcome)", check("provision: invitation email sent (merged invite + welcome)",
any("invited to the Inference Cooperative" in s for _, s in calls["email"]), str(calls["email"])) any("invited to the Inference Cooperative" in s for _, s in calls["email"]), str(calls["email"]))
check("provision: newsletter subscribed", check("provision: newsletter subscribed",
@@ -264,11 +264,11 @@ def main():
check("convert: allowance lifted to MEMBER_BUDGET", check("convert: allowance lifted to MEMBER_BUDGET",
row_of(conn, "invited@x.org", "balance") == m.MEMBER_BUDGET) row_of(conn, "invited@x.org", "balance") == m.MEMBER_BUDGET)
check("convert: unspent guest credit carried", 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", check("convert: group moved to members",
calls["group"] and calls["group"][0][1] == m.MEMBERS_GROUP_ID, str(calls["group"])) calls["group"] and calls["group"][0][1] == m.MEMBERS_GROUP_ID, str(calls["group"]))
check("convert: cap lifted to 20.00 (15 + 5 credits)", check("convert: cap lifted to 17.00 (15 + 2 credits)",
(calls["budget"] and calls["budget"][0][1] == m.MEMBER_BUDGET + 5.0), str(calls["budget"])) (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: anchor day kept", row_of(conn, "invited@x.org", "anchor_day") == anchor_before)
check("convert: congrats email sent", check("convert: congrats email sent",
any("member now" in s for _, s in calls["email"]), str(calls["email"])) 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. """Member self-serve guest requests — structurally isolated from live services.
WHY THIS EXISTS 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 invitation email) once approved, and the trial gate decides when. Every path
proven here runs against a FIXTURE database with the network layer REPLACED 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, BY A RAISING GUARD: any code path that tries to reach Cloudron, LiteLLM, OC,
@@ -25,7 +25,7 @@ WHY THIS EXISTS
members invite guests. members invite guests.
APPROVAL (the panel action) APPROVAL (the panel action)
9. Approve fires the FULL guest pipeline: row marked account_type='guest', 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 INVITING member named in it), newsletter subscribe — and the request
row becomes 'approved'. row becomes 'approved'.
10. Approving a request whose guard now refuses (state moved) records the 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 = ?", "SELECT account_type, balance, credit_balance FROM members WHERE email = ?",
("friend@x.org",)).fetchone() ("friend@x.org",)).fetchone()
check("approve: recipient row marked guest", acct and acct[0] == "guest", str(acct)) 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( ledger = conn.execute(
"SELECT inviter_email, recipient_email, status FROM guests WHERE recipient_email = 'friend@x.org'" "SELECT inviter_email, recipient_email, status FROM guests WHERE recipient_email = 'friend@x.org'"
).fetchall() ).fetchall()