Skip to content

feat(ui): cron-schedule 纯库 — 每天/每周/高级三模式 compose+parse#149

Merged
sweetcornna merged 1 commit into
mainfrom
feat/ui-cron-schedule-lib
Jul 18, 2026
Merged

feat(ui): cron-schedule 纯库 — 每天/每周/高级三模式 compose+parse#149
sweetcornna merged 1 commit into
mainfrom
feat/ui-cron-schedule-lib

Conversation

@sweetcornna

Copy link
Copy Markdown
Owner

PR-F1 — 纯 cron helper 库(无 UI 依赖)

为后续「定时器不手填 cron 表达式、改选触发时间」的 UI 重做打地基。本 PR 只落纯 lib + 测试,不动任何组件/页面

新增文件

  • ui/lib/cron-schedule.ts — 纯库,零 UI/React 依赖
  • ui/lib/cron-schedule.test.ts — vitest(24 测试)

API

  • type ScheduleState = { mode: "daily" | "weekly" | "advanced"; time: "HH:MM"; weekdays: number[](0-6, 0=周日); raw: string }
  • composeCron(state): string | null
    • dailyM H * * *
    • weeklyM H * * d,d,…
    • advanced → 原样返回 raw
    • 非法输入(坏时间、weekly 且 weekdays 为空)→ null(调用方据此禁用保存按钮)
  • parseCron(cron): ScheduleState永不抛异常,把现有任务的 cron 反解回 picker 状态
    • 非 5 段 / */N / 范围 / dom·month 非 *advancedraw 保留原串)
    • 纯整数 M/H + * * *daily;dow 为逗号整数列表 → weekly

关键设计:周日恒发 0,绝不发 7

ui/lib/api/scheduler.tsnextFireTimeDate.getDay()(只产 0-6)匹配 dow 字段,* * * * 7 匹配不到任何真实日期 → 预览为「永不触发」。因此 compose 出向把 7 → 0,parse 入向对 7 归一到 0。测试里锁定了 nextFireTime("0 12 * * 7") === null 这一行为,作为该规则的依据。

往返一致性

composeCron(parseCron(x)) 对 daily/weekly/advanced 形状还原等价表达式(7 折叠为等价的 0)。

nextFireTime 现状确认

无需改其解析逻辑:它早已支持 dow 逗号列表(matchesField, 拆分),30 21 * * 1,3,5 现在就能预览。本 PR 只补锁定测试(逗号列表命中 + dow=0 命中 + dow=7 永不命中)。

验证

  • pnpm typecheck → 0 errors
  • pnpm test → 156 files / 1211 passed / 2 skipped(含 tailwind/globals-glass 守卫测试绿)
  • pnpm lint → 仅既有 warning,未触及本 PR 文件

新增 ui/lib/cron-schedule.ts(无 UI/React 依赖),为定时器 UI 重做打基础:
- ScheduleState + composeCron(state)→cron|null + parseCron(cron)→state
- 周日恒发 0 不发 7(nextFireTime 的 dow 匹配只认 0-6)
- 非法输入返回 null 供调用方禁用保存按钮;parseCron 永不抛异常
- 往返一致性:daily/weekly 形状可等价还原
- ui/lib/cron-schedule.test.ts:往返 + 边界 + nextFireTime dow 逗号列表/dow=7 锁定测试
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added codex:needs-review A Codex review is needed for the current PR head. codex:review-requested A Codex review was requested or should be running automatically. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result. and removed codex:review-requested A Codex review was requested or should be running automatically. codex:needs-review A Codex review is needed for the current PR head. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 18, 2026
@sweetcornna
sweetcornna merged commit 12afdf0 into main Jul 18, 2026
8 of 9 checks passed
@sweetcornna
sweetcornna deleted the feat/ui-cron-schedule-lib branch July 18, 2026 17:14
@github-actions github-actions Bot added the status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. label Jul 18, 2026
sweetcornna added a commit that referenced this pull request Jul 18, 2026
接入 #149/#151/#154 落地的库与组件:
- 表格行换用 <QzoneJobRow>(run/edit/pause·resume/delete),删除旧内联行
- cron 手填换成 <QzoneSchedulePicker>(composeCron/parseCron)
- 选中人格后显示 <QzoneRefImagePicker> 选参考图(image_ref_labels)
- 新增发送抖动 jitter_minutes(0–120)输入
- 选中行就地回填编辑:parseCron 回填 picker、锁定人格、Save→Update、取消编辑
- saveMutation 按 editingName 分流 patch/create;enabled 交由行内 pause/resume
- 删除走页面级 ConfirmDialog;启停按 enabled 分流 pause/resume
- 保留一键启用每日说说 + next-fire 预览
- 新增 en+zh-CN 双份文案;新增页面测试 6 例

Co-authored-by: Cornna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex:reviewed Codex posted a review result or thumbs-up after the latest request. status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. status: 👀 ready for maintainer look No automation blocker is known; a maintainer should inspect the current result.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant