:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(wizard): drop the wizard-gateway-v2 mint gate (#120722)
Brandonaab0c97974dc
diff --git a/docs/internal/wizard-gateway-mint.md b/docs/internal/wizard-gateway-mint.mdindex b88f863d5364..822d73152b92 100644--- a/docs/internal/wizard-gateway-mint.md+++ b/docs/internal/wizard-gateway-mint.md@@ -88,11 +88,11 @@ degrades toward a floor with nothing to alert on.The endpoint answers one outcome per request, counted on`posthog_wizard_gateway_token_requests_total{outcome}`: `unconfigured`,`invalid_token`, `not_wizard_app`, `scope_missing`, `team_ambiguous`,-`team_missing`, `unauthorized`, `blocked`, `not_rolled_out`, `program_unknown`,+`team_missing`, `unauthorized`, `blocked`, `program_unknown`,`throttled`, `mint_failed`, or `minted`.Refusals that an older CLI absorbed by falling back to the legacy gateway-(`unconfigured`, `not_rolled_out`, `program_unknown`) answer 403 with a reason+(`unconfigured`, `program_unknown`) answer 403 with a reasononly to a client that sent `reads_refusal_reason: true`. Any other client stillreceives 404, which is the signal its fallback depends on. That branch retiresonce those builds are gone.diff --git a/posthog/api/wizard/http.py b/posthog/api/wizard/http.pyindex 2489a58c010f..f0a72abab5b5 100644--- a/posthog/api/wizard/http.py+++ b/posthog/api/wizard/http.py@@ -7,7 +7,6 @@ from django.conf import settingsfrom django.core.cache import cacheimport structlog-import posthoganalyticsfrom drf_spectacular.utils import extend_schemafrom prometheus_client import Counterfrom rest_framework import exceptions, serializers, status, viewsets@@ -71,7 +70,7 @@ WIZARD_GATEWAY_TOKEN_REQUESTS_TOTAL = Counter("posthog_wizard_gateway_token_requests_total","Wizard gateway-token mint requests, by outcome (minted/unconfigured/invalid_token/""not_wizard_app/scope_missing/team_ambiguous/team_missing/unauthorized/blocked/"- "program_unknown/not_rolled_out/throttled/mint_failed)",+ "program_unknown/throttled/mint_failed)",labelnames=["outcome"],)@@ -181,7 +180,7 @@ class SetupWizardViewSet(viewsets.ViewSet):_refuse_mint(outcome, exc, program=program, product_node=product, user=user, team=team)def refuse_absent_gateway(outcome: str, message: str, *, user: User | None = None) -> NoReturn:- """Refuse one of the three outcomes the CLI's legacy fallback absorbed.+ """Refuse one of the outcomes the CLI's legacy fallback absorbed.A build that still falls back needs the 404 to reach the legacygateway, which carries its own retirement message; it renders a 403@@ -278,29 +277,6 @@ class SetupWizardViewSet(viewsets.ViewSet):# The flag's refusal, word for word, so a client cannot tell which blocklist matched.refuse("blocked", exceptions.PermissionDenied(WIZARD_BLOCKED_DETAIL), user=user)- # A kill switch, not a rollout gate: only a literal False refuses. With the- # legacy product off there is no second path, so reading an outage as "not- # rolled out" turns a flag-service blip into a global wizard outage.- try:- rolled_out = posthoganalytics.feature_enabled(- "wizard-gateway-v2",- distinct_id,- groups={"organization": str(team.organization_id), "project": str(team.id)},- group_properties={"organization": {"id": str(team.organization_id)}},- only_evaluate_locally=False,- send_feature_flag_events=False,- )- except Exception as e:- logger.warning("wizard_gateway_token: rollout flag unavailable, minting", error=str(e))- rolled_out = None- else:- if rolled_out is None:- logger.warning("wizard_gateway_token: rollout flag returned no verdict, minting")- if rolled_out is False:- refuse_absent_gateway(- "not_rolled_out", "Wizard gateway tokens are switched off for this organization.", user=user- )-# Read once, after every gate that needs no flag, so an unauthenticated or# refused request costs no flag read. A policy flag that is off or broken# degrades the pin and never refuses the mint.diff --git a/posthog/api/wizard/test/test_http.py b/posthog/api/wizard/test/test_http.pyindex 27d19cc04ef6..a3ff8b0ac48d 100644--- a/posthog/api/wizard/test/test_http.py+++ b/posthog/api/wizard/test/test_http.py@@ -271,9 +271,6 @@ class SetupWizardGatewayTokenTests(APIBaseTest):)self.mock_flag_payload = payload_patch.start()self.addCleanup(payload_patch.stop)- # Patched at the endpoint's seam: the feature_enabled patches below land on- # the shared module object, so an SDK-level patch would read the rollout- # flag's value as a ban.blocklist_patch = patch("posthog.api.wizard.http.wizard_identity_blocked", return_value=False)self.mock_blocklist = blocklist_patch.start()self.addCleanup(blocklist_patch.stop)@@ -319,9 +316,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_mints_for_scoped_oauth_token(self, mock_authentication, mock_flag, mock_mint, mock_authorized):+ def test_mints_for_scoped_oauth_token(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)response = self.client.post(@@ -349,7 +345,6 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.security_access_refused")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_gateway_token_asks_the_access_rules(self,@@ -357,7 +352,6 @@ class SetupWizardGatewayTokenTests(APIBaseTest):refused: bool,expected_status: int,mock_authentication,- mock_flag,mock_mint,mock_authorized,check: MagicMock,@@ -382,11 +376,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@override_settings(DEBUG=False, WIZARD_GATEWAY_TIERS={"new": {"mints_per_week": 2}})@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_new_accounts_third_mint_in_a_day_is_throttled(- self, mock_authentication, mock_flag, mock_mint, mock_authorized- ):+ def test_a_new_accounts_third_mint_in_a_day_is_throttled(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)for _ in range(2):@@ -408,11 +399,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_the_mint_bucket_is_shared_across_programs(- self, mock_authentication, mock_flag, mock_mint, mock_authorized- ):+ def test_the_mint_bucket_is_shared_across_programs(self, mock_authentication, mock_mint, mock_authorized):"""The ceiling is per account, not per program: a second program does notget a fresh quota, or the per-account bound would scale with the program count."""self._mock_oauth(mock_authentication)@@ -433,11 +421,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@override_settings(DEBUG=False, WIZARD_GATEWAY_TIERS={"new": {"mints_per_week": 2}})@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_the_override_flag_outranks_the_tier_ceiling(- self, mock_authentication, mock_flag, mock_mint, mock_authorized- ):+ def test_the_override_flag_outranks_the_tier_ceiling(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)self.flag_payloads[WIZARD_GATEWAY_LIMIT_OVERRIDE_FLAG] = {"mints_per_week": 3}@@ -449,51 +434,11 @@ class SetupWizardGatewayTokenTests(APIBaseTest):assert mock_mint.call_count == 3- @patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=False)- @patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_flag_off_is_403_with_a_reason(self, mock_authentication, mock_flag, mock_authorized):- self._mock_oauth(mock_authentication)- response = self.client.post(- self.GATEWAY_TOKEN_URL,- {"program": "integration", "reads_refusal_reason": True},- headers={"authorization": "Bearer pha_test"},- )-- assert response.status_code == status.HTTP_403_FORBIDDEN, response.content- assert response.json()["code"] == "not_rolled_out"-- legacy = self.client.post(- self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"}- )- assert legacy.status_code == status.HTTP_404_NOT_FOUND, legacy.content-- @patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled")- @patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_rollout_flag_outage_mints(self, mock_authentication, mock_flag, mock_mint, mock_authorized):- # An outage is not a False, and must not end every wizard run.- self._mock_oauth(mock_authentication)-- for outage in ({"return_value": None}, {"side_effect": RuntimeError("flags down")}):- mock_flag.reset_mock(return_value=True, side_effect=True)- mock_flag.configure_mock(**outage)- response = self.client.post(- self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"}- )- assert response.status_code == status.HTTP_201_CREATED, (outage, response.content)-- assert mock_mint.call_count == 2-@override_settings(DEBUG=False)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_every_refusal_names_its_outcome_as_the_code(- self, mock_authentication, mock_flag, mock_mint, mock_authorized- ):+ def test_every_refusal_names_its_outcome_as_the_code(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication, scoped_teams=[self.team.id, self.team.id + 1])ambiguous = self.client.post(self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"}@@ -518,9 +463,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_blocked_identity_is_403_and_never_mints(self, mock_authentication, mock_flag, mock_mint, mock_authorized):+ def test_blocked_identity_is_403_and_never_mints(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)self.mock_blocklist.return_value = True@@ -536,10 +480,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.email_verification.is_email_available", return_value=True)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_unverified_email_is_403_and_never_mints(- self, mock_authentication, mock_flag, mock_mint, mock_authorized, _mock_email_available, _mock_disabled+ self, mock_authentication, mock_mint, mock_authorized, _mock_email_available, _mock_disabled):self._mock_oauth(mock_authentication)self.user.is_email_verified = False@@ -555,26 +498,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=False)- @patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_ban_outranks_the_rollout_gate(self, mock_authentication, mock_flag, mock_mint, mock_authorized):- # A banned account reads "blocked", not "switched off", whatever the flag says.- self._mock_oauth(mock_authentication)- self.mock_blocklist.return_value = True-- response = self.client.post(- self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"}- )-- assert response.status_code == status.HTTP_403_FORBIDDEN, response.content-- @patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_the_ban_is_asked_about_the_authenticated_identity(- self, mock_authentication, mock_flag, mock_mint, mock_authorized- ):+ def test_the_ban_is_asked_about_the_authenticated_identity(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)self.client.post(@@ -592,9 +517,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_ban_is_counted(self, mock_authentication, mock_flag, mock_mint, mock_authorized):+ def test_a_ban_is_counted(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)self.mock_blocklist.return_value = Truebefore = _gateway_token_outcome("blocked")@@ -620,9 +544,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):assert response.status_code == status.HTTP_401_UNAUTHORIZED@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=False)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_revoked_project_access_is_403(self, mock_authentication, mock_flag, mock_authorized):+ def test_revoked_project_access_is_403(self, mock_authentication, mock_authorized):self._mock_oauth(mock_authentication)response = self.client.post(self.GATEWAY_TOKEN_URL, headers={"authorization": "Bearer pha_test"})assert response.status_code == status.HTTP_403_FORBIDDEN@@ -651,9 +574,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):side_effect=WizardGatewayMintError("refused"),)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_mint_failure_is_503(self, mock_authentication, mock_flag, mock_mint, mock_authorized):+ def test_mint_failure_is_503(self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)response = self.client.post(self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"}@@ -664,11 +586,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_limit_override_raises_the_daily_ceiling(- self, mock_authentication, mock_flag, mock_authorized, mock_mint, mock_key- ):+ def test_limit_override_raises_the_daily_ceiling(self, mock_authentication, mock_authorized, mock_mint, mock_key):self._mock_oauth(mock_authentication)self.flag_payloads[WIZARD_GATEWAY_LIMIT_OVERRIDE_FLAG] = {"mints_per_week": 7}@@ -686,9 +605,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_limit_override_cap_reaches_the_mint(self, mock_authentication, mock_flag, mock_authorized, mock_mint):+ def test_limit_override_cap_reaches_the_mint(self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)self.flag_payloads[WIZARD_GATEWAY_LIMIT_OVERRIDE_FLAG] = json.dumps({"cap_usd": "30"})@@ -712,9 +630,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_flag_outage_keeps_the_default_limits(self, mock_authentication, mock_flag, mock_authorized, mock_mint):+ def test_a_flag_outage_keeps_the_default_limits(self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)self.flag_payloads[WIZARD_GATEWAY_LIMIT_OVERRIDE_FLAG] = RuntimeError("flags unavailable")@@ -738,11 +655,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_failure_that_issued_no_token_returns_the_slot(- self, mock_authentication, mock_flag, mock_authorized, mock_key- ):+ def test_a_failure_that_issued_no_token_returns_the_slot(self, mock_authentication, mock_authorized, mock_key):# Nothing below the helper's unit tests covers deleting or inverting this.self._mock_oauth(mock_authentication)with patch(@@ -759,9 +673,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@override_settings(DEBUG=False)@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_induced_failures_cannot_buy_extra_tokens(self, mock_authentication, mock_flag, mock_authorized, mock_key):+ def test_induced_failures_cannot_buy_extra_tokens(self, mock_authentication, mock_authorized, mock_key):"""The counter must equal the tokens actually issued, however many failures ran.The refund exists so an outage does not burn a user's quota, which invites@@ -802,10 +715,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_a_failure_that_may_have_issued_a_token_keeps_the_slot(- self, mock_authentication, mock_flag, mock_authorized, mock_key+ self, mock_authentication, mock_authorized, mock_key):# The paired negative: the gateway may hold this token.self._mock_oauth(mock_authentication)@@ -822,9 +734,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_unlisted_program_is_refused(self, mock_authentication, mock_flag, mock_authorized, mock_mint):+ def test_unlisted_program_is_refused(self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)response = self.client.post(self.GATEWAY_TOKEN_URL,@@ -838,10 +749,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_a_non_boolean_capability_keeps_the_compatible_status(- self, mock_authentication, mock_flag, mock_authorized, mock_mint+ self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)claimed: object@@ -858,9 +768,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_missing_program_is_refused(self, mock_authentication, mock_flag, mock_authorized, mock_mint):+ def test_missing_program_is_refused(self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)response = self.client.post(self.GATEWAY_TOKEN_URL, {"reads_refusal_reason": True}, headers={"authorization": "Bearer pha_test"}@@ -871,11 +780,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_non_string_program_is_refused_not_a_500(- self, mock_authentication, mock_flag, mock_authorized, mock_mint- ):+ def test_a_non_string_program_is_refused_not_a_500(self, mock_authentication, mock_authorized, mock_mint):# An unhashable value must be refused, not raise on the membership test.self._mock_oauth(mock_authentication)response = self.client.post(@@ -890,9 +796,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@override_settings(DEBUG=False)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_throttled_mint_is_counted(self, mock_authentication, mock_flag, mock_mint, mock_authorized):+ def test_a_throttled_mint_is_counted(self, mock_authentication, mock_mint, mock_authorized):self._ordinary_account()self._mock_oauth(mock_authentication)before = _gateway_token_outcome("throttled")@@ -910,10 +815,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.llm.wizard_gateway_token.requests.post")- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_the_flags_set_the_token_pins_and_the_prompt_stays_off_the_client(- self, mock_authentication, mock_flag, mock_post, mock_authorized+ self, mock_authentication, mock_post, mock_authorized):self._mock_oauth(mock_authentication)mock_post.return_value.status_code = 201@@ -939,11 +843,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")- def test_a_program_the_allowlist_flag_drops_is_refused(- self, mock_authentication, mock_flag, mock_authorized, mock_mint- ):+ def test_a_program_the_allowlist_flag_drops_is_refused(self, mock_authentication, mock_authorized, mock_mint):self._mock_oauth(mock_authentication)self.flag_payloads[WIZARD_GATEWAY_ALLOWLIST_FLAG] = {"models": ["claude-sonnet-5"],@@ -971,10 +872,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.llm.wizard_gateway_token.requests.post")- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_a_prompt_flag_that_is_not_usable_mints_an_unpinned_token(- self, _name, payload, mock_authentication, mock_flag, mock_post, mock_authorized, mock_key+ self, _name, payload, mock_authentication, mock_post, mock_authorized, mock_key):self._mock_oauth(mock_authentication)mock_post.return_value.status_code = 201@@ -1004,10 +904,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch.object(SetupWizardGatewayTokenRateThrottle, "get_cache_key", return_value="refund-test-key")@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.llm.wizard_gateway_token.requests.post")- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_an_allowlist_flag_that_is_not_usable_mints_with_the_defaults(- self, _name, payload, mock_authentication, mock_flag, mock_post, mock_authorized, mock_key+ self, _name, payload, mock_authentication, mock_post, mock_authorized, mock_key):self._mock_oauth(mock_authentication)mock_post.return_value.status_code = 201@@ -1051,10 +950,9 @@ class SetupWizardGatewayTokenTests(APIBaseTest):@patch("posthog.api.wizard.http.oauth_credential_authorized", return_value=True)@patch("posthog.api.wizard.http.mint_wizard_gateway_token", return_value=MINTED)- @patch("posthog.api.wizard.http.posthoganalytics.feature_enabled", return_value=True)@patch("posthog.api.wizard.http.OAuthAccessTokenAuthentication")def test_a_refusal_after_authentication_never_reads_the_policy(- self, mock_authentication, mock_flag, mock_mint, mock_authorized+ self, mock_authentication, mock_mint, mock_authorized):self._mock_oauth(mock_authentication)@@ -1062,16 +960,8 @@ class SetupWizardGatewayTokenTests(APIBaseTest):blocked = self.client.post(self.GATEWAY_TOKEN_URL, {"program": "integration"}, headers={"authorization": "Bearer pha_test"})- self.mock_blocklist.return_value = False- mock_flag.return_value = False- switched_off = self.client.post(- self.GATEWAY_TOKEN_URL,- {"program": "integration", "reads_refusal_reason": True},- headers={"authorization": "Bearer pha_test"},- )assert blocked.status_code == status.HTTP_403_FORBIDDEN, blocked.content- assert switched_off.json()["code"] == "not_rolled_out"assert self._flag_reads(WIZARD_SYSTEM_PROMPT_FLAG) == []assert self._flag_reads(WIZARD_GATEWAY_ALLOWLIST_FLAG) == []mock_mint.assert_not_called()