feat: Bark 增加开始运行与获得学分提醒

收尾通知去掉重复的积分台账与完成门数;学习统计在无 TTY 时照常累计,保证 Docker 里也能推送学分提醒。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
voidandClaude Sonnet 4.6 committed 2026-11-02 22:30:11 +08:00
1 parent 18c5e5a3be
commit 6b508a0b1a
15 files changed
+188 -51

No files matched your search

+30 -2
View File
@@ -9,7 +9,7 @@
* node dev/tests/notify-test.mjs
* npm run test:notify
*/
import { buildBarkUrl, buildFinishMessage } from '../../runner/notify.mjs';
import { buildBarkUrl, buildFinishMessage, buildStartMessage, buildCreditMessage } from '../../runner/notify.mjs';
let failed = 0;
function ok(cond, name, extra) {
@@ -53,7 +53,7 @@ console.log('收尾文案');
{
const done = buildFinishMessage({
kind: 'done',
finishReason: '脚本已停止(本次完成 10 门;无更多可学课程)',
finishReason: '无更多可学课程',
completed: 10,
elapsed: 125,
points: { enabled: true, text: '今日积分 15/24 · 文档1/1 视频3/3 音频1/2 微课0/2' },
@@ -62,6 +62,16 @@ console.log('收尾文案');
ok(done.body.indexOf('今日积分 15/24') === 0, '正文以今日积分开头');
ok(done.body.indexOf('完成 10 门 · 用时 2 分 5 秒') > 0, '完成门数与用时');
ok(done.body.indexOf('无更多可学课程') > 0, '带上结束原因');
eq(done.body.split('\n').filter((l) => l.indexOf('完成') >= 0).length, 1, '完成门数只出现一次');
const pointsDone = buildFinishMessage({
kind: 'done',
finishReason: '可用内容已学完',
completed: 4,
elapsed: 1086,
points: { enabled: true, text: '今日积分 24/24 · 文档1/1 视频3/3 音频1/2 微课0/2' },
});
ok(pointsDone.body.indexOf('(今日积分') < 0, '结束原因不再内嵌一遍积分台账');
eq(buildFinishMessage({ kind: 'stalled' }).title, '云学堂助手:长时间无进展', '卡死标题');
eq(buildFinishMessage({ kind: 'login' }).title, '云学堂助手:登录失败', '登录失败标题');
@@ -78,6 +88,24 @@ console.log('收尾文案');
'enabled=false 时只说明模式已关闭,不贴 0/24');
}
console.log('开始 / 学分通知');
{
const start = buildStartMessage({ POINTS_MODE: true, BUDGET_MINUTES: 180 });
eq(start.title, '云学堂助手:开始运行', '开始运行标题');
ok(start.body.indexOf('模式:每日积分') >= 0, '开始通知带上运行模式');
ok(start.body.indexOf('运行预算:180 分钟') >= 0, '开始通知带上运行预算');
const startFree = buildStartMessage({ POINTS_MODE: false, BUDGET_MINUTES: 0 });
ok(startFree.body.indexOf('模式:普通刷课') >= 0 && startFree.body.indexOf('运行预算:不限') >= 0,
'普通刷课 + 不限预算');
const credit = buildCreditMessage({ course: '某课程', credit: 6.52, total: 12.75, completed: 3 });
eq(credit.title, '云学堂助手:获得 6.52 学分', '学分通知标题带本次学分数');
ok(credit.body.indexOf('课程「某课程」') >= 0, '学分通知带上课程名');
ok(credit.body.indexOf('本次累计 12.75 学分 · 已完成 3 门') >= 0, '学分通知带上累计与完成门数');
eq(buildCreditMessage({ credit: 1, total: 1 }).title, '云学堂助手:获得 1 学分', '整数学分不带小数点');
}
console.log('');
if (failed) {
console.log('✘ ' + failed + ' 项失败');
+25 -3
View File
@@ -142,7 +142,29 @@ console.log('防重复计数');
}
// ---------------------------------------------------------------------------
// 5. 学分文本:浮点累加不出现 3.7499999
// 5. 学分事件:每次真正计入学分时产出 { course, credit },供 Bark 通知使用
// ---------------------------------------------------------------------------
console.log('学分事件');
{
const s = createStudyTracker({ now: clock().now });
let st = s.update({ course: 'A', credit: 2.5, completed: 0, video: video(false) });
eq(st.earned.length, 0, '只有学分、没完成时没有事件');
st = s.update({ course: 'A', credit: null, completed: 1, video: video(false) });
eq(st.earned.length, 1, '课程完成时产出一条事件');
eq(st.earned[0].course, 'A', '事件带课程名');
eq(st.earned[0].credit, 2.5, '事件带本门学分数');
eq(st.creditEarned, 2.5, '返回值里的累计学分同步更新');
st = s.update({ course: 'A', credit: null, completed: 1, video: video(false) });
eq(st.earned.length, 0, '同一门重复上报不重复产生事件');
st = s.update({ course: 'C', credit: null, completed: 2, video: video(false) });
eq(st.earned.length, 0, '没读到学分的课完成时不产生事件');
}
// ---------------------------------------------------------------------------
// 6. 学分文本:浮点累加不出现 3.7499999
// ---------------------------------------------------------------------------
console.log('学分文本');
{
@@ -155,7 +177,7 @@ console.log('学分文本');
}
// ---------------------------------------------------------------------------
// 6. 摘要 / 空状态
// 7. 摘要 / 空状态
// ---------------------------------------------------------------------------
console.log('摘要与空状态');
{
@@ -182,7 +204,7 @@ console.log('摘要与空状态');
}
// ---------------------------------------------------------------------------
// 7. reset:重开一轮(supervisor 重启的会话之间)要能清零
// 8. reset:重开一轮(supervisor 重启的会话之间)要能清零
// ---------------------------------------------------------------------------
console.log('重置');
{