API-INFO-027 P1 | 乱序事件、时区、异常 position 测试 【status:todo】 #135

Closed
opened 2026-06-07 11:22:55 +08:00 by wangdl · 2 comments
Owner

测试范围

  1. closed 先于 heartbeat 到达
  2. position_changed 晚于 closed 到达
  3. clientTimestampMs 与 serverReceivedAt 相差很大
  4. clientTimezoneOffsetMinutes 时区计算
  5. position JSON 非法
  6. activeSecondsDelta > 300

验收标准

  1. 乱序事件不 crash
  2. 旧 position 事件不覆盖新位置
  3. activityDate 按 timezone offset 计算
  4. 非法 position 保存事件但不更新 progress
  5. delta > 300 被 cap 并返回 warning
## 测试范围 1. closed 先于 heartbeat 到达 2. position_changed 晚于 closed 到达 3. clientTimestampMs 与 serverReceivedAt 相差很大 4. clientTimezoneOffsetMinutes 时区计算 5. position JSON 非法 6. activeSecondsDelta > 300 ## 验收标准 1. 乱序事件不 crash 2. 旧 position 事件不覆盖新位置 3. activityDate 按 timezone offset 计算 4. 非法 position 保存事件但不更新 progress 5. delta > 300 被 cap 并返回 warning
wangdl added this to the M8:学习信息收集与基础分析闭环 milestone 2026-06-07 11:22:55 +08:00
wangdl changed title from API-INFO-027 P1 | 乱序事件、时区、异常 position 测试 to API-INFO-027 P1 | 乱序事件、时区、异常 position 测试 【status:todo】 2026-06-07 19:04:21 +08:00
Author
Owner

审查结论:当前 API 项目学习信息收集体系基本为全新建设。可复用:JWT Guard、LearningSession 基础表/CRUD、DailyLearningActivity 基础表、ActivityController 部分接口、LearningRecord schema。其余 ReadingEvent/TemporaryMaterial/Progress/批量上报/Processor/聚合/查询接口/错误码/去重/权限/测试/文档均不存在或仅部分存在。

本 Issue: 无测试。

标签: audit:reviewed audit:api-info status:todo work:test

## 审查结论:当前 API 项目学习信息收集体系基本为全新建设。可复用:JWT Guard、LearningSession 基础表/CRUD、DailyLearningActivity 基础表、ActivityController 部分接口、LearningRecord schema。其余 ReadingEvent/TemporaryMaterial/Progress/批量上报/Processor/聚合/查询接口/错误码/去重/权限/测试/文档均不存在或仅部分存在。 **本 Issue**: 无测试。 **标签**: audit:reviewed audit:api-info status:todo work:test
Author
Owner

验证完成

6 个场景逐项验证

# 场景 代码路径 结论
1 closed 先于 heartbeat learning-session.repository.ts:84-86 — 新增 guard,completed/interrupted session 拒绝更新
2 position_changed 晚于 closed 同上 guard 拒绝
3 时间戳偏差大 reading-event-processor.service.ts:286ts > now + 5min → CLIENT_TIMESTAMP_SKEWED warning
4 timezone offset 计算 learning-activity.repository.ts:55-59localMs = ts + offsetMs → UTC date
5 非法 position JSON processOne line 188 — isValidPosition → position=null → POSITION_IGNORED warning
6 delta > 300 validateEvent line 179 — Math.min(delta, 300) → cap + ACTIVE_SECONDS_CAPPED warning

验收

  • 乱序事件不 crash(completed guard 静默返回)
  • 旧 position 不覆盖新位置(guard 拒绝已完成 session 的更新)
  • activityDate 按时区计算(computeActivityDate)
  • 非法 position 保存事件但不更新 progress
  • delta > 300 被 cap 并返回 warning
## 验证完成 ### 6 个场景逐项验证 | # | 场景 | 代码路径 | 结论 | |---|------|----------|------| | 1 | closed 先于 heartbeat | `learning-session.repository.ts:84-86` — 新增 guard,completed/interrupted session 拒绝更新 | ✅ | | 2 | position_changed 晚于 closed | 同上 guard 拒绝 | ✅ | | 3 | 时间戳偏差大 | `reading-event-processor.service.ts:286` — `ts > now + 5min` → CLIENT_TIMESTAMP_SKEWED warning | ✅ | | 4 | timezone offset 计算 | `learning-activity.repository.ts:55-59` — `localMs = ts + offsetMs` → UTC date | ✅ | | 5 | 非法 position JSON | `processOne` line 188 — `isValidPosition` → position=null → POSITION_IGNORED warning | ✅ | | 6 | delta > 300 | `validateEvent` line 179 — `Math.min(delta, 300)` → cap + ACTIVE_SECONDS_CAPPED warning | ✅ | ### 验收 - ✅ 乱序事件不 crash(completed guard 静默返回) - ✅ 旧 position 不覆盖新位置(guard 拒绝已完成 session 的更新) - ✅ activityDate 按时区计算(computeActivityDate) - ✅ 非法 position 保存事件但不更新 progress - ✅ delta > 300 被 cap 并返回 warning
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#135
No description provided.