AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Merge commit from fork
Bentlye8aa066bc25c
diff --git a/autogpt_platform/backend/backend/api/features/v1.py b/autogpt_platform/backend/backend/api/features/v1.pyindex c4b57333cf..734fb2c381 100644--- a/autogpt_platform/backend/backend/api/features/v1.py+++ b/autogpt_platform/backend/backend/api/features/v1.py@@ -829,6 +829,10 @@ async def configure_user_auto_top_up(await credit_model.top_up_credits(user_id, request.amount)else:await credit_model.top_up_credits(user_id, 0)+ except NotImplementedError as e:+ raise HTTPException(+ status_code=501, detail="Auto top-up is not available in this context"+ ) from eexcept ValueError as e:known_messages = ("must not be negative",diff --git a/autogpt_platform/backend/backend/api/features/v1_test.py b/autogpt_platform/backend/backend/api/features/v1_test.pyindex ccec8c2c66..33cce075d6 100644--- a/autogpt_platform/backend/backend/api/features/v1_test.py+++ b/autogpt_platform/backend/backend/api/features/v1_test.py@@ -580,6 +580,29 @@ def test_configure_auto_top_up(assert response.json() == "Auto top-up settings updated"+def test_configure_auto_top_up_refuses_when_model_has_no_payment_path(+ mocker: pytest_mock.MockFixture,+) -> None:+ set_auto_top_up = mocker.patch("backend.api.features.v1.set_auto_top_up")++ mock_credit_model = mocker.AsyncMock()+ mock_credit_model.get_credits.return_value = 50+ mock_credit_model.top_up_credits.side_effect = NotImplementedError(+ "Org-level Stripe top-up not yet implemented"+ )+ mocker.patch(+ "backend.api.features.v1.get_credit_model",+ return_value=mock_credit_model,+ )++ response = client.post(+ "/credits/auto-top-up", json={"threshold": 500, "amount": 500}+ )++ assert response.status_code == 501+ set_auto_top_up.assert_not_called()++def test_configure_auto_top_up_validation_errors(mocker: pytest_mock.MockFixture,) -> None:diff --git a/autogpt_platform/backend/backend/data/org_credit.py b/autogpt_platform/backend/backend/data/org_credit.pyindex 2056dcf874..6cc2c7ee01 100644--- a/autogpt_platform/backend/backend/data/org_credit.py+++ b/autogpt_platform/backend/backend/data/org_credit.py@@ -404,7 +404,10 @@ class OrgCreditModel(UserCreditBase):organization_id: str | None = None,**kwargs,):- await top_up_org_credits(self._org_id, amount, user_id=user_id)+ # Org-level billing has no payment path yet. Until top_up_intent and+ # fulfill_checkout exist, no caller may add to the org balance here;+ # promotional grants go through grant_credits explicitly.+ raise NotImplementedError("Org-level Stripe top-up not yet implemented")async def grant_credits(self,diff --git a/autogpt_platform/backend/backend/data/org_credit_test.py b/autogpt_platform/backend/backend/data/org_credit_test.pyindex 6390324aaa..88ea45dd68 100644--- a/autogpt_platform/backend/backend/data/org_credit_test.py+++ b/autogpt_platform/backend/backend/data/org_credit_test.py@@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, MagicMockimport pytestfrom backend.data.org_credit import (+ OrgCreditModel,assign_seat,get_org_credits,get_org_transaction_history,@@ -221,3 +222,25 @@ class TestSeatManagement:assert where["userId"] == "user-1"# Verify status set to INACTIVEassert call_kwargs["data"]["status"] == "INACTIVE"+++class TestOrgCreditModelTopUp:+ @pytest.mark.asyncio+ async def test_top_up_credits_refuses_without_payment_path(self, mock_prisma):+ mock_prisma.query_raw = AsyncMock(return_value=[{"balance": 500}])++ with pytest.raises(NotImplementedError, match="not yet implemented"):+ await OrgCreditModel("org-1").top_up_credits("user-1", 500)++ mock_prisma.query_raw.assert_not_called()+ mock_prisma.orgcredittransaction.create.assert_not_called()++ @pytest.mark.asyncio+ async def test_grant_credits_still_writes_the_ledger(self, mock_prisma):+ mock_prisma.query_raw = AsyncMock(return_value=[{"balance": 500}])++ result = await OrgCreditModel("org-1").grant_credits("user-1", 500, "promo")++ assert result == 500+ mock_prisma.query_raw.assert_called_once()+