Files
life-echo/api/tests/test_error_code_registry.py
Sully 105b50a277 merge dark mode and google OAuth (#35)
* feat(api): implement Google OAuth login and user management

- Added Google OpenID Connect login functionality, allowing users to authenticate using their Google accounts.
- Created new endpoints for Google login, including user registration and linking existing accounts.
- Introduced Google token verification logic and error handling for authentication failures.
- Updated environment configuration to include Google OAuth client IDs and verification settings.
- Enhanced user model to support OpenID and linked Google accounts.

This feature improves user experience by enabling seamless sign-in with Google, while maintaining security and integrity of user data.

* fix(auth): wire staging Google token verifier

* chore(deps): update expo to version 55.0.6 and adjust @expo/env dependency in pnpm-lock.yaml

* chore(deps): update Babel dependencies to version 7.29.7 in package-lock.json

* feat(auth): enhance phone login for China users

- Updated phone login functionality to support only mainland China (+86) mobile numbers.
- Added user prompts and descriptions for phone login, including confirmation and cancellation options.
- Adjusted translations for both English and Chinese to reflect the new phone login requirements.
- Updated Google OAuth client IDs in configuration files for production and staging environments.

* chore(deps): add peer flag to use-sync-external-store in package-lock.json

* chore(deps): add @emnapi/core and @emnapi/runtime to package-lock.json

* fix(app-expo): align Android native dependencies

* fix(app-expo): normalize lockfile for npm 10

* fix(config): update environment variable handling to use static access

- Introduced a static mapping for public environment variables to ensure proper access during the release bundle.
- Updated the `requirePublicEnv` and `optionalPublicEnv` functions to reference the new `PUBLIC_ENV` object instead of directly accessing `process.env`.
- Added comments to clarify the necessity of static access for certain environment variables.

* feat(app-expo): dark mode, FAQ i18n, eval ASR, and theme cleanup (#34)

* feat(app-expo): dark mode, FAQ i18n, version CI, and theme cleanup

Implement light/dark scene colors across chat, reading, and headers; remove
default/brand theme picker and ThemeVariablesProvider. Localize FAQ in-app,
fix dark-mode text visibility, and remove the unused /api/faqs endpoint.
Align About/version with Expo config and inject APP_VERSION in CI builds.

Also includes phone E164 auth/SMS updates, eval ASR page, and related API work.

* revert: remove phone E.164 changes from dark-mode branch

These auth/SMS internationalization updates were accidentally bundled into
the dark-mode commit; restore 11-digit CN phone flow and drop related API,
migration, and Expo UI work from this branch.

* fix: address PR review issues for dark mode and eval ASR

Use light foreground colors for sepia reading in dark mode, fix chat send
button contrast, stream-limit eval ASR uploads, restore LiveTester phone
validation, and remove unused AudioSegmenter code.

* fix(app-expo): improve chat send button contrast in light and dark mode

Add dedicated send button colors (accent fill in dark, primary fill in
light), use RNText to avoid NativeWind overrides, and restore dark labels
in light mode for readable composer actions.

---------

Co-authored-by: Kevin <kevin@brighteng.org>

---------

Co-authored-by: penghanyuan <penghanyuan@gmail.com>
Co-authored-by: Kevin <kevin@brighteng.org>
2026-06-09 11:14:36 +08:00

118 lines
3.6 KiB
Python

"""Ensure runtime error_code values stay within the OpenAPI registry."""
from __future__ import annotations
import re
from pathlib import Path
import pytest
from app.core.error_codes import ALL_ERROR_CODES, ERROR_CODE_ENUM
from app.core.errors import (
_STATUS_TO_ERROR_CODE,
AppError,
AuthenticationError,
AuthorizationError,
BadRequestError,
ConflictError,
GatewayTimeoutError,
NotFoundError,
ProviderError,
QuotaExceededError,
RateLimitedError,
ServiceUnavailableError,
ValidationError,
)
from app.features.auth.service_errors import _AUTH_CODE_MAP
from app.features.payment.payment_exceptions import _PAYMENT_CODE_MAP
_APP_FEATURES_ROOT = Path(__file__).resolve().parents[1] / "app" / "features"
_LITERAL_ERROR_CODE_RE = re.compile(r"""error_code\s*=\s*["']([A-Z][A-Z0-9_]*)["']""")
def _app_error_subclass_codes() -> set[str]:
codes: set[str] = set()
for cls in (
NotFoundError,
BadRequestError,
AuthenticationError,
AuthorizationError,
ValidationError,
ConflictError,
ServiceUnavailableError,
GatewayTimeoutError,
ProviderError,
QuotaExceededError,
RateLimitedError,
):
# Instantiate with defaults to read resolved error_code from AppError base.
instance = cls()
codes.add(instance.error_code)
return codes
def _auth_runtime_codes() -> set[str]:
return {external for _, external in _AUTH_CODE_MAP.values()}
def _payment_runtime_codes() -> set[str]:
return {external for _, external in _PAYMENT_CODE_MAP.values()}
def _literal_feature_error_codes() -> set[str]:
codes: set[str] = set()
for path in _APP_FEATURES_ROOT.rglob("*.py"):
text = path.read_text(encoding="utf-8")
codes.update(_LITERAL_ERROR_CODE_RE.findall(text))
return codes
def _runtime_error_codes() -> set[str]:
return (
_app_error_subclass_codes()
| _auth_runtime_codes()
| _payment_runtime_codes()
| set(_STATUS_TO_ERROR_CODE.values())
| _literal_feature_error_codes()
)
def test_runtime_error_codes_are_registered_in_openapi_enum() -> None:
runtime = _runtime_error_codes()
registry = set(ERROR_CODE_ENUM)
missing = runtime - registry
assert not missing, f"Unregistered runtime error_code values: {sorted(missing)}"
def test_auth_and_payment_registry_http_status_matches_runtime_maps() -> None:
registry_by_code = {entry["code"]: entry for entry in ALL_ERROR_CODES}
for internal, (status_code, external) in {**_AUTH_CODE_MAP, **_PAYMENT_CODE_MAP}.items():
if external not in registry_by_code:
continue
entry = registry_by_code[external]
assert entry["http_status"] == status_code, (
f"{internal} maps to {external} with HTTP {status_code}, "
f"but registry lists {entry['http_status']}"
)
@pytest.mark.parametrize(
"error_cls,expected_code",
[
(NotFoundError, "NOT_FOUND"),
(BadRequestError, "BAD_REQUEST"),
(AuthenticationError, "AUTHENTICATION_FAILED"),
(AuthorizationError, "FORBIDDEN"),
(ValidationError, "VALIDATION_ERROR"),
(ConflictError, "CONFLICT"),
(ServiceUnavailableError, "SERVICE_UNAVAILABLE"),
(GatewayTimeoutError, "GATEWAY_TIMEOUT"),
(ProviderError, "PROVIDER_ERROR"),
(QuotaExceededError, "QUOTA_EXCEEDED"),
(RateLimitedError, "RATE_LIMITED"),
],
)
def test_app_error_subclasses_use_registered_codes(error_cls: type[AppError], expected_code: str) -> None:
assert error_cls().error_code == expected_code
assert expected_code in ERROR_CODE_ENUM