fix(qdreader): harden cron trigger detection

This commit is contained in:
2026-05-22 21:14:36 +08:00
parent aae3fc2ba2
commit a7792012a1
4 changed files with 66 additions and 36 deletions
+22
View File
@@ -55,6 +55,7 @@ function runPlugin({ pluginCode = code, filename = pluginPath, content = '', sto
if (String(req.url).includes('/sign')) return { body: { code: 0, data: { headers: { 'QD-Sign': 'sig' } } } };
return { statusCode: 200, body: { code: 0, msg: '签到成功' } };
},
input: () => '',
...globals,
};
vm.createContext(ctx);
@@ -717,6 +718,27 @@ test('manual sign replies per account first and summary separately for multi-acc
assert.match(r.replies[2], /日志已归档/);
});
test('cron detection uses ImType cron and does not consume input as command text', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
};
const r = runPlugin({
content: '',
store,
userId: 'cron',
globals: {
ImType: () => 'cron',
input: () => 'q',
Date: fixedDateClass('2026-05-19T07:01:00.000+08:00'),
},
});
assert.equal(r.calls.length, 4);
assert.equal(r.replies.length, 1);
assert.match(r.replies[0], /汇总:成功 1 \/ 失败 0 \/ 总计 1/);
assert.match(r.replies[0], /定时任务\/零点任务/);
});
test('manual sign only runs current user accounts while cron runs all accounts', () => {
const store = {
qdreader_cookie_json: JSON.stringify({ '12345': cookie, '67890': cookie.replace(/12345/g, '67890') }),