fix(qdreader): use single cron for archive and sign

This commit is contained in:
2026-05-19 16:43:05 +08:00
parent 557b5ae9c2
commit 36717c3887
5 changed files with 29 additions and 33 deletions
+7 -7
View File
@@ -266,7 +266,7 @@ test('midnight cron archives previous run log and clears daily logs without runn
});
test('five-minute delayed midnight cron still archives instead of signing', () => {
test('single cron midnight branch archives without signing', () => {
const previousRun = {
runId: '20260518_cron',
source: 'cron',
@@ -282,20 +282,20 @@ test('five-minute delayed midnight cron still archives instead of signing', () =
qdreader_last_run_json: JSON.stringify(previousRun),
qdreader_last_result_json: JSON.stringify({ '12345': JSON.stringify({ ok: true, msg: '昨日签到成功' }) }),
};
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T00:04:00.000+08:00') } });
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T00:01:00.000+08:00') } });
assert.equal(r.calls.length, 0);
assert.match(r.replies[0], /日志归档完成/);
assert.equal(JSON.parse(r.store.qdreader_archive_json)['2026-05-18'].runId, '20260518_cron');
});
test('after five-minute midnight window cron follows sign path', () => {
test('single cron morning branch signs without archiving', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
qdreader_last_run_json: JSON.stringify({ source: 'cron', finishedAt: '2026-05-18T07:15:02.000Z', total: 1, okCount: 1, failCount: 0, items: [{ uid: '12345', ok: true }] }),
};
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T00:05:00.000+08:00') } });
const r = runPlugin({ content: '', store, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(r.calls.length, 2);
assert.match(r.replies[0], /启点读书签到结果/);
assert.equal(r.store.qdreader_archive_json, undefined);
@@ -346,7 +346,7 @@ test('manual sign and cron sign both call sign gateway then qidian checkin', ()
assert.equal(payload.qdh, 'qdh');
assert.equal(payload.qdheader, 'MTIzNDV8eA==');
const cron = runPlugin({ content: '', store: { ...store }, globals: { Date: fixedDateClass('2026-05-19T07:15:00.000+08:00') } });
const cron = runPlugin({ content: '', store: { ...store }, globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 2);
assert.match(cron.replies[0], /启点读书签到结果/);
assert.equal(JSON.parse(cron.store.qdreader_last_run_json).source, 'cron');
@@ -527,7 +527,7 @@ test('manual sign only runs current user accounts while cron runs all accounts',
const manual = runPlugin({ content: '启点签到', store: { ...store }, userId: 'user-a' });
assert.equal(manual.calls.length, 2);
assert.match(manual.replies[0], /总计 1/);
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:15:00.000+08:00') } });
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 4);
assert.match(cron.replies[0], /总计 2/);
});
@@ -541,7 +541,7 @@ test('unbound global cookies are not visible or usable by normal users', () => {
assert.equal(manual.calls.length, 0);
assert.match(manual.replies[0], /还没有保存启点读书CK/);
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:15:00.000+08:00') } });
const cron = runPlugin({ content: '', store: { ...store }, userId: 'cron', globals: { Date: fixedDateClass('2026-05-19T07:01:00.000+08:00') } });
assert.equal(cron.calls.length, 2);
assert.match(cron.replies[0], /总计 1/);
});