@@ -50,7 +50,16 @@ function parseArgs(argv) {
function formatRunAtLocal ( epochMs , timezone = tz ) {
const parts = getLocalParts ( epochMs , timezone ) ;
return ` ${ parts . year } - ${ String ( parts . month ) . padStart ( 2 , '0' ) } - ${ String ( parts . day ) . padStart ( 2 , '0' ) } ${ String ( parts . hour ) . padStart ( 2 , '0' ) } : ${ String ( parts . minute ) . padStart ( 2 , '0' ) } ` ;
let minute = parts . minute ;
let hour = parts . hour ;
if ( parts . second > 0 ) {
minute += 1 ;
if ( minute >= 60 ) {
minute = 0 ;
hour += 1 ;
}
}
return ` ${ parts . year } - ${ String ( parts . month ) . padStart ( 2 , '0' ) } - ${ String ( parts . day ) . padStart ( 2 , '0' ) } ${ String ( hour ) . padStart ( 2 , '0' ) } : ${ String ( minute ) . padStart ( 2 , '0' ) } ` ;
}
function testIntentLayer ( ) {
@@ -195,7 +204,7 @@ async function testLivePortalWorker(pool, userId, { dueSeconds }) {
const created = await scheduledTaskService . createTask ( {
userId ,
title : ` ${ TEST _TITLE _PREFIX } live_portal ` ,
taskSpec : '用三句话总结今天的热点新闻(验证脚本,回复文本即可,不要生成页面) ' ,
taskSpec : '【验证】直接回复一行文字:验证成功。禁止追问、禁止生成页面、禁止调用任何工具。 ' ,
recurrence : 'once' ,
runAtLocal : formatRunAtLocal ( runAtMs , tz ) ,
notifyChannel : 'web' ,
@@ -203,10 +212,16 @@ async function testLivePortalWorker(pool, userId, { dueSeconds }) {
} ) ;
pass ( 'Live 任务已创建' , ` ${ waitSeconds } s 后执行,id= ${ created . id } ` ) ;
console . log ( ` \n 等待 Portal worker 执行(最多 ${ waitSeconds + 120 } s)… ` ) ;
const executionTimeoutMs = Number (
process . env . H5 _SCHEDULED _TASK _EXECUTION _TIMEOUT _MS
? ? process . env . VERIFY _SCHEDULED _TASK _EXECUTION _TIMEOUT _MS
? ? 180_000 ,
) ;
const waitBudgetMs = waitSeconds * 1000 + executionTimeoutMs + 60_000 ;
console . log ( ` \n 等待 Portal worker 执行(最多 ${ Math . ceil ( waitBudgetMs / 1000 ) } s,含 Agent 超时 ${ Math . ceil ( executionTimeoutMs / 1000 ) } s)… ` ) ;
console . log ( '请确认 Portal 进程已开启 scheduled task worker( H5_SCHEDULED_TASK_WORKER_ENABLED=1,或未设置时 H5_REMINDER_WORKER_ENABLED=1) \n' ) ;
const deadline = Date . now ( ) + ( waitSeconds + 120 ) * 1000 ;
const deadline = Date . now ( ) + waitBudgetMs ;
let terminal = null ;
while ( Date . now ( ) < deadline ) {
const [ rows ] = await pool . query (
@@ -214,6 +229,11 @@ async function testLivePortalWorker(pool, userId, { dueSeconds }) {
[ created . id ] ,
) ;
terminal = rows [ 0 ] ;
if ( ! terminal ) {
fail ( 'Live Portal worker' , ` 任务 ${ created . id } 在数据库中消失 ` ) ;
await cleanupTestRows ( pool , userId ) ;
return ;
}
if ( terminal ? . status === 'completed' || terminal ? . status === 'failed' ) break ;
await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
}
@@ -222,6 +242,10 @@ async function testLivePortalWorker(pool, userId, { dueSeconds }) {
pass ( 'Live Portal worker' , ` 任务 completed, updated_at= ${ terminal . updated _at } ` ) ;
} else if ( terminal ? . status === 'failed' ) {
fail ( 'Live Portal worker' , terminal . last _error ? ? 'failed' ) ;
} else if ( terminal ? . status === 'running' ) {
fail ( 'Live Portal worker' , ` Agent 仍在执行中(status=running);可提高 H5_SCHEDULED_TASK_EXECUTION_TIMEOUT_MS 或检查 Goose 连通性 ` ) ;
} else if ( terminal ? . status === 'active' && terminal ? . last _error ) {
fail ( 'Live Portal worker' , ` 已失败并重试调度: ${ terminal . last _error } ` ) ;
} else {
fail ( 'Live Portal worker' , ` 超时,最后 status= ${ terminal ? . status ? ? 'unknown' } ` ) ;
}