fix(ci): DATABASE_URL 必填後 CI 單元測試報 ValidationError 修復
Some checks failed
CD Pipeline / build-and-deploy (push) Failing after 41s

C4 安全修復移除 changeme 預設值後,Pydantic Settings 在 CI 環境找不到
DATABASE_URL 導致 import chain 崩潰(pydantic_core.ValidationError)。

單元測試本身不連 DB,只需 Settings 能初始化。加入 CI placeholder:
  DATABASE_URL="${DATABASE_URL:-postgresql+asyncpg://ci:ci@localhost/ci}"
若 CI 已注入真實 secret 則使用真實值;否則使用 localhost placeholder。

影響範圍:cd.yaml Run API Tests、cd-dev.yaml Run API Tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-04-22 01:35:19 +08:00
parent 479f8d8971
commit 5e353407f7
2 changed files with 5 additions and 0 deletions

View File

@@ -65,6 +65,8 @@ jobs:
fi
cd apps/api
# 2026-04-22 ogt: DATABASE_URL 改為必填,單元測試需要此 env var 讓 Settings 通過驗證
DATABASE_URL="${DATABASE_URL:-postgresql+asyncpg://ci:ci@localhost/ci}" \
pytest tests/ -v --tb=short -x \
--ignore=tests/test_anomaly_counter.py \
--ignore=tests/test_global_repair_cooldown.py \

View File

@@ -128,6 +128,9 @@ jobs:
# 原問題: import src.main → asyncpg C ext segfault (exit 139)
# 修復: 改用最小化 app只掛載 github_webhook router不走 DB import chain
# 現在可安全加入 CI 測試
# 2026-04-22 ogt: DATABASE_URL 改為必填後,單元測試需要此 env var 讓 Settings 通過驗證
# 單元測試不連 DB此 CI placeholder 僅供 Pydantic 驗證,不產生真實連線
DATABASE_URL="${DATABASE_URL:-postgresql+asyncpg://ci:ci@localhost/ci}" \
PYTHONFAULTHANDLER=1 python3.11 -m pytest tests/ -v --tb=short -x \
--ignore=tests/integration \
--ignore=tests/test_anomaly_counter.py \