a1a921eba6
Pass cancel requests to Goose like create instead of inbound title matching, and add scheduled_task_update_spec so format or execution constraints update taskSpec without triggering page delivery guards. Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { handleWechatScheduledTaskIntent } from './scheduled-task.mjs';
|
|
|
|
test('handleWechatScheduledTaskIntent passes create requests to goose', async () => {
|
|
const reply = await handleWechatScheduledTaskIntent({
|
|
intent: {
|
|
msgType: 'text',
|
|
agentText: '每天6点帮我做今日新闻页面',
|
|
msgId: 'msg-1',
|
|
},
|
|
user: { userId: 'user-1' },
|
|
scheduledTaskService: {
|
|
async createTask() {
|
|
throw new Error('should not create from inbound regex');
|
|
},
|
|
},
|
|
});
|
|
assert.equal(reply, null);
|
|
});
|
|
|
|
test('handleWechatScheduledTaskIntent passes incomplete create requests to goose', async () => {
|
|
const reply = await handleWechatScheduledTaskIntent({
|
|
intent: {
|
|
msgType: 'text',
|
|
agentText: '帮我设一个定时自动任务',
|
|
msgId: 'msg-1',
|
|
},
|
|
user: { userId: 'user-1' },
|
|
scheduledTaskService: {
|
|
async createTask() {
|
|
throw new Error('should not create from inbound regex');
|
|
},
|
|
},
|
|
});
|
|
assert.equal(reply, null);
|
|
});
|
|
|
|
test('handleWechatScheduledTaskIntent passes cancel requests to goose', async () => {
|
|
const reply = await handleWechatScheduledTaskIntent({
|
|
intent: {
|
|
msgType: 'text',
|
|
agentText: '取消定时推送苏州天气任务',
|
|
msgId: 'msg-123-1',
|
|
},
|
|
user: { userId: 'user-123' },
|
|
scheduledTaskService: {
|
|
async cancelTask() {
|
|
throw new Error('should not cancel from inbound regex');
|
|
},
|
|
},
|
|
});
|
|
assert.equal(reply, null);
|
|
});
|
|
|
|
test('handleWechatScheduledTaskIntent ignores non automation text', async () => {
|
|
const reply = await handleWechatScheduledTaskIntent({
|
|
intent: {
|
|
msgType: 'text',
|
|
agentText: '明天下午三点提醒我开会',
|
|
msgId: 'msg-1',
|
|
},
|
|
user: { userId: 'user-1' },
|
|
scheduledTaskService: {
|
|
async createTask() {
|
|
throw new Error('should not create');
|
|
},
|
|
},
|
|
});
|
|
assert.equal(reply, null);
|
|
});
|
|
|
|
test('handleWechatScheduledTaskIntent still lists tasks', async () => {
|
|
const reply = await handleWechatScheduledTaskIntent({
|
|
intent: {
|
|
msgType: 'text',
|
|
agentText: '看看我的定时自动任务',
|
|
msgId: 'msg-1',
|
|
},
|
|
user: { userId: 'user-1' },
|
|
scheduledTaskService: {
|
|
async listTasks() {
|
|
return [{ title: '新闻页面', recurrence: 'daily', hour: 6, minute: 0, timezone: 'Asia/Shanghai' }];
|
|
},
|
|
},
|
|
});
|
|
assert.match(reply, /新闻页面/u);
|
|
});
|