Files
memind/scheduled-task-executor.test.mjs
john 049d8a6f80
Memind CI / Test, build, and release guards (push) Has been cancelled
fix(scheduled-task): enable worker by default and add WeChat preflight
Scheduled automations were saved but never executed because the worker
required an explicit env flag. Follow H5_REMINDER_WORKER_ENABLED when unset,
add WeChat preflight to write tasks deterministically, and surface worker
warnings on create.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 19:32:09 +08:00

57 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
buildScheduledTaskExecutionPrompt,
extractScheduledTaskDeliveryText,
formatScheduledTaskDeliveryMessage,
looksLikeScheduledTaskNonDelivery,
} from './scheduled-task-executor.mjs';
test('buildScheduledTaskExecutionPrompt includes task spec and automation marker', () => {
const message = buildScheduledTaskExecutionPrompt({
id: 'task-1',
title: '每日新闻页',
taskSpec: '搜索今日新闻并生成 HTML 页面',
recurrence: 'daily',
timezone: 'Asia/Shanghai',
});
const text = message.content[0].text;
assert.match(text, /scheduled-task-automation/);
assert.match(text, /每日新闻页/);
assert.match(text, /搜索今日新闻并生成 HTML 页面/);
assert.match(text, /Scheduled Automation/);
assert.match(text, /禁止调用 scheduled_task_create/);
});
test('looksLikeScheduledTaskNonDelivery detects clarification replies', () => {
assert.equal(
looksLikeScheduledTaskNonDelivery('请问 7月31日具体几点执行这个任务?'),
true,
);
assert.equal(
looksLikeScheduledTaskNonDelivery('页面已生成:https://example.com/news.html'),
false,
);
assert.equal(
looksLikeScheduledTaskNonDelivery('好的', { readyPaths: ['public/news.html'] }),
false,
);
});
test('extractScheduledTaskDeliveryText reads last assistant message', () => {
const text = extractScheduledTaskDeliveryText([
{ role: 'user', content: [{ type: 'text', text: 'hi' }] },
{ role: 'assistant', content: [{ type: 'text', text: '今日新闻页:https://example.com/news.html' }] },
], { title: '每日新闻页' });
assert.match(text, /https:\/\/example.com\/news.html/);
});
test('formatScheduledTaskDeliveryMessage wraps delivery body', () => {
const text = formatScheduledTaskDeliveryMessage(
{ title: '每日新闻页' },
'页面已生成:https://example.com/news.html',
);
assert.match(text, /定时任务完成:每日新闻页/);
assert.match(text, /页面已生成/);
});