✨ feat(schedule): 查询最近十五分钟日程操作 - #175
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@fennoai 你是资深后端/全栈架构师 + 嵌入式硬件工程师复合型专家,执行严格、客观、不留情面的代码仓库Review,请遵循下面所有评审规则,逐条输出审查结果,禁止敷衍、禁止只说空话、禁止笼统概括。 评审维度
输出要求
现在开始对提供的仓库代码/PR变更、硬件资料、结构模型进行评审 |
严格 Review 结果按固定范围 审查条目
顶层设计问题当前 PR 把“操作记录”设计成独立可写的公共业务能力,并用进程全局 mock 存储承接真实 Store 的职责。这会把权限校验、用户隔离、事务一致性、撤销状态、容量治理全部推迟到未来,导致现在的接口形状已经不利于真实落库。正确边界应是:日程写操作在同一事务内产生日志;查询只读当前用户、未撤销、时间窗口内记录;撤销在同一事务内恢复快照并标记日志已撤销。 ① 整体仓库风险总结本 PR 的纯筛选 helper 本身逻辑清晰,闭区间和同秒倒序测试覆盖到了;但服务级实现仍是全局 mock、无锁、无界、无用户上下文。对后端一致性和嵌入式长稳运行而言,主要风险不是算法写错,而是接口边界过早暴露了不可信写入和无限内存增长。硬件驱动层未被本 PR 直接触碰,未发现直接烧毁外设或机构失控代码路径;但无界堆增长和并发数据竞争会造成固件级崩溃/复位,同样阻断上机长期测试。 ② 优先级整改清单阻断项优先:先修全局 mock store 的互斥与容量/TTL 清理;再补用户/设备上下文和 Store 查询契约;随后禁止外部伪造操作记录,把记录写入并入 create/update/delete 事务;最后校验 previous 快照完整性和 schedule_id 一致性。 强制补测:增加 previous mismatch/非法 previous、并发写读、过期记录服务级过滤、15 分钟内大批量记录、重复撤销状态过滤用例。 ③ 长期架构与软硬件协同优化方案建立 |
|
|
||
| /** @brief 返回进程内的操作记录集合。 @return 可变的操作记录集合。 */ | ||
| std::deque<OperationRecord>& MockOperations() { | ||
| static std::deque<OperationRecord> operations; |
There was a problem hiding this comment.
🔴 This process-global deque and the adjacent ID counter are shared by all callers, but neither the append path nor the read path takes a lock. Concurrent schedule writes/queries can race, corrupt the history, or duplicate IDs; there is also no prune/reset path, so the store grows without bound on long-running firmware.
| QueryRecentScheduleOperationResult ScheduleService::query_recent_schedule_operation() const { | ||
| const DateTime now = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()); | ||
|
|
||
| // TODO(#121):真实存储接入用户上下文后,由存储层按当前用户和十五分钟时间窗口查询。 |
There was a problem hiding this comment.
🔴 The TODO here notes user scoping is still missing, but the public API has no parameter for user/device identity. As written, query_recent_schedule_operation() can only return the process-global history, so once this is backed by a real store it will mix and potentially expose other callers' operations instead of 'the current user's recent operations'.
结论
本 PR 实现
ScheduleService::query_recent_schedule_operation(),返回当前设备用户在当前时间往前 15 分钟内的全部日程操作,并提供确定性的倒序结果。请 Reviewer 重点判断 15 分钟闭区间、取消 10 条限制、同秒排序规则,以及设备单用户 mock 与未来真实用户隔离的边界是否合理。本 PR 依赖 #174。由于 #174 尚未合并且其 head 位于 fork,本分支暂时包含 #174 的提交;建议先合并 #174,再合并本 PR。
Refs #176
变更
ScheduleService::query_recent_schedule_operation()。[now - 15min, now]内的全部操作。operated_at倒序排列,同秒记录按operation_id倒序排列。OperationRecord::previous,返回操作前完整Schedule快照。schedule_recent_operation_test,覆盖空结果、窗口边界、未来记录、倒序、重复查询和超过 10 条的场景。schedule_operation_test,验证 mock 存储不再按记录条数裁剪。明确未包含:
架构与兼容
不新增 Port、Profile、外部协议或组件依赖方向。公共结果结构未增加字段,继续返回
QueryRecentScheduleOperationResult和 #174 定义的OperationRecord;仅将查询注释从“最近十条”修正为“最近十五分钟内”。mock 存储由固定 10 条容量改为不按条数裁剪,这是为了满足“返回 15 分钟内全部操作”的查询契约。真实存储接入后,应在 Store 层按当前用户和时间窗口过滤,并保持相同的排序语义。
验证
./scripts/run_pre_submit_checks.sh证据:
CLANG_FORMAT=<llvm@18>/bin/clang-format RUFF=/Users/mac/.local/share/uv/tools/ruff/bin/ruff ./scripts/check_format.sh通过,16 个相关文件均已格式化。./scripts/run_host_tests.sh -L schedule通过,7/7 日程测试通过。./scripts/run_pre_submit_checks.sh完整通过:23 个主机测试、29 个 Python 测试和 126 个 IM Gateway 测试通过,公共 API 文档、架构、双端契约、esp32s3-devProfile 与idf.py build均通过。TDD 记录
schedule_recent_operation_test后,基线缺少query_recent_schedule_operation()定义,且 ✨ feat(schedule): 实现日程操作记录接口 #174 的 mock 会将超过 10 条的场景裁剪,无法满足查询契约。schedule_operation_query_helpers纯函数,通过显式now消除测试对系统时间和sleep的依赖;同秒使用操作 ID 倒序保证结果稳定。风险与回退
6db8b1d;✨ feat(schedule): 实现日程操作记录接口 #174 的操作记录接口可独立保留。