Files
beabigegg 64874d5425 feat: enhance weekly report and realtime notifications
Weekly Report (fix-weekly-report):
- Remove 5-task limit, show all tasks per category
- Add blocked tasks with blocker_reason and blocked_since
- Add next week tasks (due in coming week)
- Add assignee_name, completed_at, days_overdue to task details
- Frontend collapsible sections for each task category
- 8 new tests for enhanced report content

Realtime Notifications (fix-realtime-notifications):
- SQLAlchemy event-based notification publishing
- Redis Pub/Sub for multi-process broadcast
- Fix soft rollback handler stacking issue
- Fix ping scheduling drift (send immediately when interval expires)
- Frontend NotificationContext with WebSocket reconnection

Spec Fixes:
- Add missing ## Purpose sections to 5 specs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 20:52:08 +08:00

1.5 KiB

MODIFIED Requirements

Requirement: Real-time Notifications

系統 SHALL 透過 WebSocket 與 Redis Pub/Sub 推播即時通知。

Scenario: 即時通知推播

  • GIVEN 發生需要通知的事件(如:被指派任務、被 @提及、阻礙標記)
  • WHEN NotificationService.create_notification() 執行
  • THEN 系統透過 Redis Pub/Sub 發布通知至 notifications:{user_id} channel
  • AND 訂閱該 channel 的 WebSocket 連線接收訊息
  • AND ConnectionManager 推送通知給使用者的 WebSocket

Scenario: 連線時補送未讀

  • GIVEN 使用者建立 WebSocket 連線
  • WHEN 連線驗證成功
  • THEN 系統查詢該使用者的未讀通知 (is_read = false)
  • AND 透過 unread_sync 訊息一次推送所有未讀通知
  • AND 開始訂閱 Redis channel 接收新通知

Scenario: 心跳偵測

  • GIVEN 使用者已建立 WebSocket 連線
  • WHEN 連線超過心跳間隔無回應
  • THEN 系統將連線標記為斷線並從 ConnectionManager 移除

MODIFIED Technical Notes

  • 使用 Redis Pub/Sub 處理即時通知推播
  • WebSocket 連線管理:
    • ConnectionManager 維護 user_id → WebSocket[] 映射
    • 心跳偵測清理斷線連線
    • Token 驗證透過 query parameter
  • 通知推播流程:
    1. NotificationService.create_notification() 建立通知
    2. 呼叫 redis_pubsub.publish_notification() 發布
    3. 訂閱該 user channel 的 worker 收到訊息
    4. ConnectionManager.send_to_user() 推送給連線的 WebSocket