Files
awoooi/docs/HARD_RULES.md
OG T 9bff46a1b0 feat: integrate Sentry + fix CI/CD issues
Sentry Integration (補強 SignOz):
- Add @sentry/nextjs for frontend error tracking + session replay
- Add sentry-sdk[fastapi] for backend error tracking
- Create sentry.client/server/edge.config.ts
- Integrate with next.config.js + instrumentation.ts
- Add Sentry exception capture in FastAPI error handler
- Create deployment scripts for Self-Hosted @ 192.168.0.110

CI/CD Fixes:
- Fix F821 Undefined name 'Field' in incidents.py
- Add NEXT_PUBLIC_API_URL env var to CI build step
- Add build-arg to Docker build verification

E2E Test Improvements:
- Fix strict mode violations in dashboard-acceptance tests
- Add timeout increase for Phase 4 demo tests
- Make tests more resilient to UI variations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-24 15:19:52 +08:00

224 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AWOOOI 絕對禁止規則 (Hard Rules)
> 違反任何一條 = 重大事故
## 快速索引
| 主題 | 禁止 | 正確做法 | 詳細規則 |
|------|------|---------|---------|
| CI/CD | `ubuntu-latest` | `self-hosted` | [→ GitHub Billing](#github-billing) |
| Telegram | `logOut()` | 先停後換 | [→ Telegram Token](#telegram-token) |
| 前端 | 硬編碼文字 | `next-intl` | [→ i18n](#i18n) |
| 資料庫 | SQLite | PostgreSQL | [→ DB](#database) |
| CORS | `*` | 白名單 | [→ CORS](#cors) |
| 數據 | 假數據 Demo | 真實 API | [→ No Fake Data](#no-fake-data) |
| 架構 | 刪除 OpenClaw | OpenClaw 是核心 | [→ OpenClaw](#openclaw) |
| Git | `--force` | 正常 push | [→ Git Safety](#git-safety) |
| **測試** | **Mock 測試** | **真實 DB/服務** | [→ No Mock Testing](#no-mock-testing) |
| **API** | **單獨改路徑** | **前後端同步** | [→ API Path Naming](#api-path-naming) |
| **部署** | **假設已部署** | **驗證 Pod 版本** | [→ Deployment Verification](#deployment-verification) |
---
## GitHub Billing
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_github_billing.md`
```yaml
# ❌ 禁止
runs-on: ubuntu-latest
# ✅ 正確
runs-on: self-hosted
```
**原因:** GitHub Actions 帳戶額度限制,必須用 192.168.0.110 的 self-hosted runner。
---
## Telegram Token
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_telegram_token_disaster.md`
```python
# ❌ 禁止 - 會導致 Token 永久失效
await bot.log_out()
# ✅ 正確流程
1. 先停止舊 Bot Long Polling
2. 再切換新 Token
```
**原因:** 2026-03-23 災難事件logOut 導致 Token 永久失效。
---
## i18n
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_i18n_zero_hardcode.md`
```tsx
// ❌ 禁止
<button>Submit</button>
// ✅ 正確
<button>{t('common.submit')}</button>
```
**原因:** 100% 雙語支援 (zh-TW + en)。
---
## Database
**Memory:** AWOOOI 憲法
```python
# ❌ 禁止
DATABASE_URL = "sqlite:///..."
# ✅ 正確
DATABASE_URL = "postgresql+asyncpg://..."
```
**原因:** SQLite 無法支援生產環境並發。
---
## CORS
**Memory:** AWOOOI 憲法
```python
# ❌ 禁止
CORS_ORIGINS = ["*"]
# ✅ 正確
CORS_ORIGINS = ["https://awoooi.wooo.work", "http://localhost:3000"]
```
**原因:** 安全性要求。
---
## No Fake Data
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_no_fake_data.md`
```tsx
// ❌ 禁止
const data = DEMO_DATA
// ✅ 正確
const { data } = useRealAPI()
```
**原因:** 假數據導致用戶無法看到真實系統狀態。
---
## OpenClaw
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_architecture_openclaw_core.md`
```
❌ 禁止: 淘汰、取代、或刪除 OpenClaw
✅ 正確: OpenClaw 是 AWOOOI 產品核心,只能增強不能移除
```
**原因:** OpenClaw AI 是產品核心價值。
---
## Git Safety
**Memory:** 防禦性工程
```bash
# ❌ 禁止
git push --force
git reset --hard
git checkout -- .
# ✅ 正確
git push
git revert
```
**原因:** 防止資料遺失。
---
## API Path Naming
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_api_path_naming.md`
```python
# ❌ 禁止 - 單獨修改後端路徑
@router.get("/ai-performance") # 改成 /incidents/ai-performance
# 但前端仍調用 /ai-performance → 404
# ✅ 正確 - 前後端同步修改
# 1. 後端: @router.get("/incidents/ai-performance")
# 2. 前端: await fetch('/api/v1/stats/incidents/ai-performance')
# 3. 測試: curl 驗證
```
**原因:** 路徑變更是破壞性變更,必須同時更新前後端。
---
## No Mock Testing
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_no_mock_testing.md`
```python
# ❌ 禁止 - 全面禁止 Mock 測試
from unittest.mock import Mock, AsyncMock, MagicMock, patch
mock_service = AsyncMock()
with patch("src.services.xxx", mock_service):
...
# ✅ 正確 - 使用真實資料庫/服務
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.post("/api/v1/xxx", json=payload)
```
**原因:** 統帥 2026-03-24 明確指示「全面禁止」Mock 無法反映真實系統行為。
**允許例外:**
- `patch.object(settings, ...)` 修改配置值(非 Mock 服務)
---
## Deployment Verification
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_deployment_verification.md`
```bash
# ❌ 禁止 - 假設 git push 就是部署完成
git push && echo "已部署"
# ✅ 正確 - 必須驗證 Pod 實際運行版本
# 1. 確認 CD workflow 成功
gh run list --workflow=cd.yaml --limit 1 # 必須 ✅ success
# 2. 驗證 Pod 鏡像版本
kubectl get pods -n awoooi-prod -o jsonpath="{.items[*].spec.containers[*].image}"
# 鏡像 tag 必須與最新 commit SHA 匹配
# 3. Health check
curl -f https://api.awoooi.wooo.work/api/v1/health
```
**原因:** 2026-03-24 重大事故:代碼已提交但 CD 連續失敗,正式環境仍運行舊版本,用戶誤以為功能已修復。
---
## 如何新增規則
1. 在此文件新增章節
2. 更新快速索引表
3. 在 Memory 新增對應 `feedback_*.md`
4. 更新 `MEMORY.md` 索引