f43ed6f116
用户口径(2026-11-03,33179 卡 80%「正在提交检测」的救援出口):任务卡片加
「中断/继续」;中断后已完成检测的数据生成结果文件供下载,未完成行不再检测;
继续在原任务上续跑剩余行(断点续传,已检测行不重检)。
中断(POST /api/tasks/{taskId}/interrupt,鉴权镜像 retry:resolveOwnershipUserId
+归属校验,普通账号只能中断自己名下的任务;终态重按幂等 no-op):
- TaskHeartbeatService.markCancelledByUser:ACTIVE→CANCELLED 条件更新(词表走
TaskStatuses.FileTask 常量),写「用户中断任务,已完成部分可下载」+finished_at,
syncTerminalState 同步模块缓存与进度快照;客户端心跳拿到 notAlive 即协作停止
(app_client/maixiang 零改动,≤60s 自停)。
- LLM 批循环批间查终态即停:当前批跑完不再发新批(isOwningTaskTerminal)。
- 中断任务的组装跳过候选申领/LLM/补检,直接按已有行账出部分表(allowPartial),
状态保持 CANCELLED 不改写,只补行账缺口文案;cleanupResultFileJob 对 CANCELLED
任务保留分片/范围态/瞬态载荷(这就是「继续」的续跑点),常规交付照旧清理。
继续(retry 链路放宽 CANCELLED,全部在原任务上):
- retryInPlace 条件更新放宽 FAILED/CANCELLED;CAS 前经 ResultFileJobHandler
新钩子 onTaskResumed 清模块补检预算(AP:删 __recheck__ 哨兵键;不清则继续后
第一轮就被「预算耗尽」直接按部分表收尾,钩子抛错即中止不留半态)。
- 中断已交付过的:清 result.result_file_url/size(让位给新表)+把 SUCCESS 的
ASSEMBLE_RESULT 作业复位 PENDING(retry/stuck 计数清零、清错误与 finished_at);
FAILED 仍走既有 resetTerminalFailedForRecovery。
- 校验文案「只有失败或已中断的任务可以继续」;成功任务不可继续。
前端(用户端外观专利 Tab 先行,后端端点本身通用):中断按钮进当前/历史两个
动作槽(确认框说明「未完成行不再检测、已完成检测的数据会生成结果文件供下载」);
CANCELLED 显示「已中断」(判定先于 isResultPreparing,不掉「等待中」兜底);
重试按钮文案 CANCELLED→「继续」,继续的确认框警示部分结果文件将被替换请先下载;
轮询收敛集合与 keepPendingFileTask 补 CANCELLED。棘轮:前端 catch 块 310→311
(interruptTaskRecord 一支,两处 ElMessageBox 确认走 .then 两臂不新增 catch);
状态词表全走 TaskStatuses 常量。
测试:TaskHeartbeatServiceTest +4(CAS 落库+缓存同步/终态幂等/非本人 403/
任务不存在明确报错)、TaskInPlaceRetryServiceTest +3(继续复位+作业复位+
补检钩子只对 CANCELLED 触发/成功不可继续)、新增 AppearancePatentInterrupted
ResumeTest(3)(保留分片=续跑点/常规交付照旧清理/中断收尾不改写状态)与
AppearancePatentLlmBatchPipelineInterruptTest(2)(批间终态即停);后端定向
79+22 全绿。前端新增 appearance-patent-interrupt-continue.test.ts(9);npm test
1003/1003、test:mount 55/55、vue-tsc 零错;ops 快检 overall=pass(grep 需
Git usr/bin 在 PATH,两红格系本机 shell 环境非代码红)。
并发边界:同工作树另一会话的在飞件(TaskFileJobService 卡死归属守卫、
TaskResultFileJobWorker、DeliverySupport 补检闸及其 3 支测试、useLiveTaskBoard、
task-delete 三件)未卷入本提交;本提交不依赖其中任何符号(appendDeliveryGapMessage/
resetTerminalFailedForRecovery/registry.asMap 均在 HEAD 已在)。
111 lines
5.4 KiB
TypeScript
111 lines
5.4 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { resolve, dirname } from 'node:path'
|
|
import { taskStatusClass, taskStatusText } from '../src/shared/utils/task-status-text.ts'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const tabSource = readFileSync(
|
|
resolve(here, '../src/pages/brand/components/BrandAppearancePatentTab.vue'),
|
|
'utf-8',
|
|
)
|
|
const apiSource = readFileSync(
|
|
resolve(here, '../src/shared/api/types/modules/appearance-patent.ts'),
|
|
'utf-8',
|
|
)
|
|
|
|
function functionBody(name: string): string {
|
|
const match = tabSource.match(new RegExp(`function ${name}\\([\\s\\S]*?\\n\\}`))
|
|
assert.ok(match, `找不到函数 ${name}`)
|
|
return match[0]
|
|
}
|
|
|
|
// ---- 状态显示:已中断不能掉进「等待中」兜底(task-status-text.ts 点名过的取消态误显形状)----
|
|
|
|
test('test_cancelled_status_shows_interrupted_text', () => {
|
|
const body = functionBody('statusText')
|
|
const cancelledIdx = body.indexOf("'CANCELLED'")
|
|
assert.ok(cancelledIdx >= 0, 'statusText 缺少 CANCELLED 分支')
|
|
assert.match(body, /已中断/, 'CANCELLED 必须显示「已中断」')
|
|
// CANCELLED 分支必须先于结果生成中/已判死等分支(它自己就是终态,不用等文件)
|
|
const preparingIdx = body.indexOf('isResultPreparing(item)')
|
|
assert.ok(cancelledIdx < preparingIdx, 'CANCELLED 必须在 isResultPreparing 之前判定')
|
|
})
|
|
|
|
test('test_cancelled_class_uses_failed_style_from_shared_map', () => {
|
|
const body = functionBody('statusClass')
|
|
assert.match(body, /taskStatusClass\('CANCELLED'\)/, 'CANCELLED 样式必须由公共映射产出')
|
|
assert.equal(taskStatusClass('CANCELLED'), 'failed', '公共映射里 CANCELLED 应产出 failed 样式')
|
|
assert.equal(taskStatusText('CANCELLED'), '已取消', '公共文案表必须认 CANCELLED(别让别的 Tab 掉兜底)')
|
|
})
|
|
|
|
// ---- 中断按钮:在跑/待跑可中断,点按有确认、调对接口、动作后刷新 ----
|
|
|
|
test('test_interrupt_button_conditions_cover_active_states', () => {
|
|
const body = functionBody('canInterruptTask')
|
|
assert.match(body, /item\?\.taskId/, '没有 taskId 的行不能显示中断')
|
|
for (const status of ['PENDING', 'RUNNING', 'SCHEDULED']) {
|
|
assert.ok(body.includes(`'${status}'`), `ACTIVE 态 ${status} 必须可中断`)
|
|
}
|
|
// 终态(SUCCESS/FAILED/CANCELLED)不得出现在可中断集合里
|
|
assert.ok(!body.includes("'SUCCESS'"), '终态任务不该显示中断按钮')
|
|
})
|
|
|
|
test('test_interrupt_action_confirms_then_calls_api_and_refreshes', () => {
|
|
const body = functionBody('interruptTaskRecord')
|
|
const confirmIdx = body.indexOf('ElMessageBox.confirm')
|
|
const apiIdx = body.indexOf('interruptAppearancePatentTask(')
|
|
assert.ok(confirmIdx >= 0, '中断必须先弹确认框(未完成行不再检测是用户要知道的后果)')
|
|
assert.match(body, /已完成检测的数据会生成结果文件/, '确认文案要说明中断后已完成部分可下载')
|
|
assert.ok(apiIdx > confirmIdx, '确认通过后才调中断接口')
|
|
assert.match(body, /refreshBoard\(\)/, '中断后必须刷新任务面板')
|
|
})
|
|
|
|
test('test_interrupt_button_rendered_in_both_action_slots', () => {
|
|
const template = tabSource.slice(0, tabSource.indexOf('<script'))
|
|
const currentSlot = template.indexOf('#item-actions')
|
|
const historySlot = template.indexOf('#history-item-actions')
|
|
assert.ok(currentSlot >= 0 && historySlot > currentSlot, '模板缺当前/历史两个动作槽')
|
|
assert.equal(
|
|
(template.match(/btn-interrupt/g) || []).length, 2,
|
|
'中断按钮必须同时出现在当前任务与历史任务两个动作槽',
|
|
)
|
|
})
|
|
|
|
// ---- 继续:已中断任务复用重试链路,文案与确认语义不同 ----
|
|
|
|
test('test_retry_accepts_cancelled_and_labels_continue', () => {
|
|
const retryBody = functionBody('canRetryTask')
|
|
assert.ok(retryBody.includes("'FAILED'") && retryBody.includes("'CANCELLED'"),
|
|
'重试条件必须放宽到已中断(继续)')
|
|
const labelBody = functionBody('retryLabel')
|
|
assert.match(labelBody, /'CANCELLED'/, '按钮文案必须按 CANCELLED 切换')
|
|
assert.match(labelBody, /继续/, '已中断的任务显示「继续」')
|
|
})
|
|
|
|
test('test_continue_warns_about_partial_file_replacement', () => {
|
|
const body = functionBody('retryTaskRecord')
|
|
const confirmIdx = body.indexOf('ElMessageBox.confirm')
|
|
const apiIdx = body.indexOf('retryAppearancePatentTask(')
|
|
assert.ok(confirmIdx >= 0, '带部分结果的中断任务点「继续」要弹确认')
|
|
assert.match(body, /请先下载留存/, '确认文案要提醒部分结果文件将被替换')
|
|
assert.ok(apiIdx > confirmIdx, '确认通过后才调重试接口')
|
|
})
|
|
|
|
// ---- API:走通用中断端点,带 user_id 归属 ----
|
|
|
|
test('test_interrupt_api_uses_generic_task_endpoint', () => {
|
|
const body = apiSource.match(/export function interruptAppearancePatentTask[\s\S]*?\n\}/)
|
|
assert.ok(body, '缺少 interruptAppearancePatentTask API')
|
|
assert.match(body[0], /\/tasks\/\$\{taskId\}\/interrupt/, '必须打 POST /api/tasks/{taskId}/interrupt')
|
|
assert.match(body[0], /user_id/, '必须带 user_id(普通账号只能中断自己名下的任务)')
|
|
})
|
|
|
|
// ---- 轮询收敛:已中断任务要能脱离轮询,不能一直挂「处理中」 ----
|
|
|
|
test('test_polling_settles_on_cancelled', () => {
|
|
assert.match(tabSource, /settleOnTaskStatuses: \['SUCCESS', 'FAILED', 'CANCELLED'\]/,
|
|
'CANCELLED 必须在轮询收敛集合里')
|
|
})
|