Skip to content

fix: parseDueDate 增加合理性校验 - #131

Merged
lishuceo merged 2 commits into
mainfrom
feat/claude-session-cff7db
Mar 10, 2026
Merged

fix: parseDueDate 增加合理性校验#131
lishuceo merged 2 commits into
mainfrom
feat/claude-session-cff7db

Conversation

@lishuceo

Copy link
Copy Markdown
Owner

Summary

  • parseDueDate() 解析完时间戳后增加合理性校验:不能是过去、不能超过 1 年后
  • create/update 响应回显 YYYY-MM-DD 人类可读日期,方便调用方立刻发现异常
  • 测试改用动态时间戳(相对于当前时间),避免硬编码日期过期导致 CI 失败

Background

创建飞书任务时传入 due: "2026-03-13" + is_all_day: true,工具产生了错误的时间戳 1728000000(对应 2024-10-04),飞书 UI 按毫秒级解释后显示为 1970 年。根因是工具对解析结果缺少合理性校验,错误值静默传入了 API。

Test plan

  • 44 个 vitest 测试全部通过(含 5 个新增校验用例)
  • 部署后验证创建任务传过去日期会报错
  • 验证创建任务响应包含人类可读日期

🤖 Generated with Claude Code

- 解析完时间戳后校验:不能是过去、不能超过 1 年后,否则报错并附带人类可读日期
- create/update 响应回显 YYYY-MM-DD 日期,方便调用方立刻发现异常
- 测试改用动态时间戳,避免硬编码日期过期导致 CI 失败

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lishuceo
lishuceo force-pushed the feat/claude-session-cff7db branch from 0af6dd7 to 56bc4d1 Compare March 10, 2026 11:29
@claude

claude Bot commented Mar 10, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 28s —— View job


PR Review: parseDueDate 合理性校验

  • Check for previous review comments
  • Read changed files and understand context
  • Perform code review
  • Post review summary

⚠️ Issues Found

Overall this is a well-structured PR that solves a real bug (wrong timestamps silently passed to Feishu API). The refactor from early-return to let seconds with a single validation gate is clean, and switching tests to dynamic timestamps is the right call.

1 issue found:

  • 🟡 All-day tasks set to "today" will be rejected (confidence: 80) — parseDueDate("2026-03-10") parses to UTC midnight, which is in the past for most of the day. Users can never create an all-day task due today. See inline comment for a suggested fix using todayMidnight alignment.

What looks good:

  • Validation logic is sound for the general case (past rejection + 1-year cap)
  • Human-readable date echo in create/update responses aids debugging
  • Error messages include both the parsed date and original input — very helpful
  • Tests cover all new validation branches (past timestamps, past ISO dates, >1 year future, human-readable in errors)
  • Dynamic test dates prevent future CI breakage from hardcoded dates expiring

Comment thread src/feishu/tools/task.ts
将过期校验的基准从当前时间改为当天 UTC 午夜,
避免设置全天任务截止"今天"时被误拒。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 10, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 20s —— View job


PR Review: parseDueDate 合理性校验 (re-review after sync)

  • Check for previous review comments and resolve fixed issues
  • Read updated source files
  • Perform code review
  • Post review summary

✅ Approved

1 previous issue fixed: "today" dates are now correctly allowed by aligning the comparison to todayMidnight = now - (now % 86400) (line 64-66). Test coverage added at line 154-158.

No new issues found. The changes in this sync commit cleanly address the previous review feedback:

  • parseDueDate() validation logic is sound — past dates rejected (against UTC midnight), future >1 year rejected, today allowed
  • Human-readable date echo added to both create and update responses
  • Tests use dynamic timestamps relative to Date.now(), preventing future CI failures from hardcoded dates
  • All 5 new validation test cases cover the expected branches (past timestamp, past ISO, today allowed, >1 year timestamp, >1 year ISO, human-readable in errors)

@lishuceo
lishuceo merged commit bd9c380 into main Mar 10, 2026
4 checks passed
@lishuceo
lishuceo deleted the feat/claude-session-cff7db branch March 10, 2026 11:41
lishuceo added a commit that referenced this pull request Apr 8, 2026
* fix: parseDueDate 增加合理性校验,防止错误时间戳静默传入飞书 API

- 解析完时间戳后校验:不能是过去、不能超过 1 年后,否则报错并附带人类可读日期
- create/update 响应回显 YYYY-MM-DD 日期,方便调用方立刻发现异常
- 测试改用动态时间戳,避免硬编码日期过期导致 CI 失败

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: parseDueDate 允许"今天"作为截止日期

将过期校验的基准从当前时间改为当天 UTC 午夜,
避免设置全天任务截止"今天"时被误拒。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant