fix(google-chat): avoid guessing auth failure cause

This commit is contained in:
Jony
2026-09-14 11:24:45 +08:00
committed by brooklyn!
parent ac4181fdfa
commit f588166691
2 changed files with 20 additions and 1 deletions

View File

@@ -690,7 +690,10 @@ class GoogleChatAdapter(BasePlatformAdapter):
"""Run streaming_pull with exponential backoff + full jitter; fatal after N attempts.
``subscribe()`` returns a Future that resolves when the stream dies."""
pubsub_fatals = {
gax_exceptions.Unauthenticated: ("pubsub_auth", "Pub/Sub authentication failed (SA key invalid/revoked)"),
gax_exceptions.Unauthenticated: (
"pubsub_auth",
"Pub/Sub authentication failed; check service-account credentials and gateway logs",
),
gax_exceptions.PermissionDenied: ("pubsub_permission", "SA lacks pubsub.subscriber on the subscription"),
}
attempt = 0

View File

@@ -1518,6 +1518,22 @@ class TestADCFallback:
class TestSupervisorReconnect:
@pytest.mark.asyncio
async def test_unauthenticated_status_does_not_guess_credential_cause(
self, adapter
):
"""An auth rejection may have causes other than a revoked SA key."""
adapter._subscriber.subscribe.side_effect = (
_gc_mod.gax_exceptions.Unauthenticated("request rejected")
)
await adapter._run_supervisor()
assert adapter.fatal_error_code == "pubsub_auth"
assert adapter.fatal_error_message == (
"Pub/Sub authentication failed; check service-account credentials and gateway logs"
)
@pytest.mark.asyncio
async def test_fatal_after_max_retries(self, adapter, monkeypatch):
"""Simulate 10+ failing subscribe() calls and assert fatal error set."""