1737903ec7
- 删除 17 个被测模块已不存在的测试(api-field-schemas / build-chunk-planner /
polling-state-machine 等),套件 94 -> 77 文件
- polling-unknown-status 只保留仍接线的 useTaskProgressLoop 两条,去掉状态机用例
- endpoints 快照重钉 218 -> 215(漂移恰好等于外观专利 parsed-payload/queue-payload/
activate 三个下线端点,无新增、无取值变化)
- brand-rows-version-wiring 的轻量失败回退断言改用 [^}] 锁进 catch 体内:
原窗口会跨过 catch 右花括号读到后面正常分支的 return { taskIds, force: true },
删掉回退也照样绿;五处变异(三页 heavyIds = ids + 外观页两种写法)现全部转红
- appearance-patent-failed-status 改为断言公共映射 taskStatusClass('FAILED')
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { useTaskProgressLoop } from '../src/shared/composables/useTaskProgressLoop.ts'
|
|
|
|
function fakeWindow() {
|
|
const storage = new Map<string, string>()
|
|
;(globalThis as Record<string, unknown>).window = {
|
|
localStorage: {
|
|
getItem: (k: string) => storage.get(k) ?? null,
|
|
setItem: (k: string, v: string) => { storage.set(k, v) },
|
|
removeItem: (k: string) => { storage.delete(k) },
|
|
},
|
|
setTimeout: (fn: () => void, ms: number) => globalThis.setTimeout(fn, ms),
|
|
clearTimeout: (id: unknown) => globalThis.clearTimeout(id as number),
|
|
setInterval: (fn: () => void, ms: number) => globalThis.setInterval(fn, ms),
|
|
clearInterval: (id: unknown) => globalThis.clearInterval(id as number),
|
|
}
|
|
}
|
|
|
|
test('test_unknown_status_continues_polling', async () => {
|
|
fakeWindow()
|
|
const terminalCalls: number[] = []
|
|
const loop = useTaskProgressLoop<{ taskId?: number; status?: string }>({
|
|
scope: 'unknown-status',
|
|
fetchProgress: async () => ({ items: [{ taskId: 1, status: 'MYSTERY' }] }),
|
|
extractTaskId: (d) => d?.taskId,
|
|
extractStatus: (d) => d?.status,
|
|
getIntervalMs: () => 60000,
|
|
onTerminal: (taskId) => { terminalCalls.push(taskId) },
|
|
})
|
|
loop.reset([1])
|
|
await new Promise<void>((r) => globalThis.setTimeout(r, 0))
|
|
await loop.refreshOnce()
|
|
assert.deepEqual(loop.taskIds.value, [1], '未知状态任务仍在轮询集合')
|
|
assert.equal(terminalCalls.length, 0, '未知状态不触发终态回调')
|
|
loop.dispose()
|
|
})
|
|
|
|
test('test_mixed_terminal_unknown', async () => {
|
|
fakeWindow()
|
|
const terminalCalls: number[] = []
|
|
const all = [
|
|
{ taskId: 1, status: 'SUCCESS' },
|
|
{ taskId: 2, status: 'QUEUED' },
|
|
{ taskId: 3, status: 'FAILED' },
|
|
]
|
|
const loop = useTaskProgressLoop<{ taskId?: number; status?: string }>({
|
|
scope: 'mixed-status',
|
|
fetchProgress: async (ids) => ({
|
|
items: all.filter((item) => ids.includes(item.taskId ?? -1)),
|
|
}),
|
|
extractTaskId: (d) => d?.taskId,
|
|
extractStatus: (d) => d?.status,
|
|
getIntervalMs: () => 60000,
|
|
onTerminal: (taskId) => { terminalCalls.push(taskId) },
|
|
})
|
|
loop.reset([1, 2, 3])
|
|
await new Promise<void>((r) => globalThis.setTimeout(r, 0))
|
|
await loop.refreshOnce()
|
|
assert.deepEqual(terminalCalls, [1, 3], '同批终态+未知分开处理')
|
|
assert.deepEqual(loop.taskIds.value, [2], '未知状态任务保留')
|
|
loop.dispose()
|
|
})
|