feat(points): P2 step 1 - POINTS_ENABLED safety gate (default false) #1936

Merged
auto-approve-bot merged 5 commits from feat/points-gate-config into develop 2026-09-16 00:26:29 +08:00
Owner

#1895 P2 第 1 步:积分系统配置安全闸门

按要求先补总开关,再逐个路由接入 @points_gate,确保 P2 阶段合入后对现有用户零影响。

改动

  1. packages/config/base.py SharedSettings 新增 points_enabled: bool = False(pydantic-settings 大小写不敏感,自动支持 POINTS_ENABLED=true 环境变量)
  2. .env.example 新增 POINTS_ENABLED=false 配置项及注释说明
  3. packages/middleware/points_gate.py 新增模块级函数 _points_gate_enabled() 读取开关:
    • 默认 false(开关未开)时,@points_gate 装饰器完全透传原函数,零开销零副作用,不读 user/db、不扣点、不抛 401/402
    • true 时执行原有扣费/401/402/异常自动退费逻辑
    • 配置加载失败默认关闭(fail-closed,安全)
  4. 测试:
    • test_config_base.py 加 4 个用例:默认 false、环境变量 true、关闭时装饰器透传、开启时强制鉴权
    • test_points_gate.py 所有用例加 autouse fixture monkeypatch.setattr(_points_gate_enabled, lambda: True),确保原有 10 个测试继续覆盖开启时的行为

验证

  • 本地 15442 passed, 28 skipped(全量单测)
  • black + ruff 全部通过
  • 开关默认 false,staging 合入后对现有用户完全无影响

后续 PR 计划(按你给的优先级):

  • TTS 合成/试听(routes/tts.py + voice_clones.py preview)
  • 口型同步(routes/lipsync.py)
  • 文案 AI(routes/scripts_ai.py 三端点)
  • 视频生成(routes/generation_tasks.py)
  • 视频预览(routes/generation_preview.py)
  • AI 数字人(routes/ai_avatar_render.py)
  • 封面生成(routes/generation_cover.py)
  • 注册送积分(routes/auth.py)
## #1895 P2 第 1 步:积分系统配置安全闸门 按要求先补总开关,再逐个路由接入 @points_gate,确保 P2 阶段合入后对现有用户零影响。 ### 改动 1. **`packages/config/base.py` SharedSettings** 新增 `points_enabled: bool = False`(pydantic-settings 大小写不敏感,自动支持 `POINTS_ENABLED=true` 环境变量) 2. **`.env.example`** 新增 `POINTS_ENABLED=false` 配置项及注释说明 3. **`packages/middleware/points_gate.py`** 新增模块级函数 `_points_gate_enabled()` 读取开关: - 默认 false(开关未开)时,`@points_gate` 装饰器完全透传原函数,零开销零副作用,不读 user/db、不扣点、不抛 401/402 - true 时执行原有扣费/401/402/异常自动退费逻辑 - 配置加载失败默认关闭(fail-closed,安全) 4. **测试**: - `test_config_base.py` 加 4 个用例:默认 false、环境变量 true、关闭时装饰器透传、开启时强制鉴权 - `test_points_gate.py` 所有用例加 autouse fixture `monkeypatch.setattr(_points_gate_enabled, lambda: True)`,确保原有 10 个测试继续覆盖开启时的行为 ### 验证 - 本地 15442 passed, 28 skipped(全量单测) - black + ruff 全部通过 - 开关默认 false,staging 合入后对现有用户完全无影响 后续 PR 计划(按你给的优先级): - [ ] TTS 合成/试听(routes/tts.py + voice_clones.py preview) - [ ] 口型同步(routes/lipsync.py) - [ ] 文案 AI(routes/scripts_ai.py 三端点) - [ ] 视频生成(routes/generation_tasks.py) - [ ] 视频预览(routes/generation_preview.py) - [ ] AI 数字人(routes/ai_avatar_render.py) - [ ] 封面生成(routes/generation_cover.py) - [ ] 注册送积分(routes/auth.py)
xiaoxia added 1 commit 2026-09-15 18:40:39 +08:00
feat(points): P2 step 1 - add POINTS_ENABLED safety gate with default false
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m33s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m53s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m56s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m7s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 20h42m53s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 20h42m58s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 20h43m2s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 20h43m4s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 20h42m17s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 20h42m17s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 20h42m21s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 20h42m21s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 20h42m23s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 20h42m23s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 20h42m24s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 20h42m12s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 20h42m16s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 20h42m18s
f587b7a44d
- Add points_enabled: bool = False to SharedSettings (packages/config/base.py)
- Add POINTS_ENABLED=false to .env.example with documentation
- Add _points_gate_enabled() module-level helper in points_gate middleware
- When disabled (default), @points_gate decorator is pure pass-through (zero side effects)
- When enabled, existing deduct/refund/402/401/500 logic activates as before
- Add 4 unit tests covering: default false / env override / disabled passthrough / enabled enforcement
- Fix existing points_gate tests to monkeypatch _points_gate_enabled=True (since default is now off)
- Total: 15442 passed, 28 skipped; black/ruff clean

🚀 预览环境已部署

项目 详情
PR号 #1936
预览链接 https://pr-1936.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1936 | | 预览链接 | [https://pr-1936.preview.xiaoxiajianji.com](https://pr-1936.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-09-15 18:44:39 +08:00
style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 28s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 55s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m21s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m1s
AI Code Review / AI Code Review (pull_request) Successful in 6m42s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 20h38m15s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 20h38m15s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 20h38m16s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 20h38m22s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 20h38m57s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 20h38m16s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 20h38m17s
7aa5e56cd6
xiaoxia closed this pull request 2026-09-15 18:44:47 +08:00
xiaoxia reopened this pull request 2026-09-15 18:44:52 +08:00

🗑️ 预览环境已清理

PR #1936 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1936 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
xiaoxia added 1 commit 2026-09-15 18:53:17 +08:00
chore: trigger CI
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 54s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 34s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 56s
PR Automation / Auto Approve on CI Green (pull_request) Failing after 2h3m11s
AI Code Review / AI Code Review (pull_request) Failing after 2h3m14s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 18h12m7s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 20h29m10s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 20h29m22s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 20h30m24s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 20h29m12s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 20h29m37s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 20h28m25s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 20h28m33s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 20h28m33s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 20h29m43s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 20h29m43s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 20h29m45s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 0s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 0s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 18h11m25s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 0s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 20h28m23s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 20h28m25s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 20h29m36s
8343a1211e
xiaoxia added 1 commit 2026-09-15 22:52:05 +08:00
fix(points): make @points_gate wrapper inherit decorated module globals
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 4s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m27s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m57s
AI Code Review / AI Code Review (pull_request) Successful in 6m54s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 17s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 18s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 11m43s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 11m36s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 16h18m33s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 16h17m51s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 16h17m52s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 16h17m51s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 16h17m50s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 16h30m30s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 16h17m51s
61d998bb01
Previously the async/sync wrappers were defined inside the points_gate
module, so wrapper.__globals__ pointed to packages.middleware.points_gate
instead of the route module. When FastAPI/Pydantic resolved ForwardRef
type annotations (e.g. Pydantic models imported only in the route
module), they hit PydanticUndefinedAnnotation in environments where
typing.get_type_hints didn't walk __wrapped__ (Python 3.12 fast path).

Fix: clone the wrapper code via types.FunctionType into the decorated
function's module globals (with internal helpers injected), and use
_filter_kwargs consistently in all call paths (async passthrough and
gate-enabled paths included).
auto-approve-bot added 1 commit 2026-09-15 23:19:14 +08:00
style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m48s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m44s
AI Code Review / AI Code Review (pull_request) Successful in 6m43s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 11s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 11s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 6m12s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m23s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 6m19s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m58s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 15m2s
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m12s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 10s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 38s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 14h57m51s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 15h3m27s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 15h22m12s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 15h25m29s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 14h55m34s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 15h2m44s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 15h2m44s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 15h24m45s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 15h24m45s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 15h24m50s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 14h55m1s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 14h57m8s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 14h57m8s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 14h50m42s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 14h26m37s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 14h50m43s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 14h50m43s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 15h21m27s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 15h35m56s
c8b0425986
auto-approve-bot merged commit 00045131f6 into develop 2026-09-16 00:26:29 +08:00
auto-approve-bot deleted branch feat/points-gate-config 2026-09-16 00:26:30 +08:00

🗑️ 预览环境已清理

PR #1936 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1936 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.