fix(通知): 麦象不可读不再折叠成「无异常」、探活 4xx 不冒充正常、交付不完整独立成 scene,前端入队拒绝按机器码决定重试
- MaixiangConsoleClient 新增 probeReadable/classifyReadout,把四种「读不出来」的形状与
「确实无异常」分开;MaixiangAnomalyScanner 在六项扫描前先过这道闸,读不通就喊一条
天级去重的管理员异常并退出本轮——此前后台挂掉时六项一致报「无异常」,服务探测还是绿的。
- NotificationScanScheduler 的探活改三态 ALIVE/UNVERIFIED/DOWN:401/403/404 说明请求被
挡在业务之外,拿不到健康证据,不能再按 <500 判成「服务正常」。
- task_partial(交付不完整)从 task_failed 里拆出来独立成 scene,仍归任务异常大类;
NotificationDispatchService 的管理员行改用 SCENE_TASK_PARTIAL。
- 前端 dispatch-guard 用机器码 shop_busy/queue_full 判定「等一会儿再推就会成」,
暂缓 20s×15 封顶;此前页面靠 includes('当前店铺正在执行中') 匹配中文,而文案中间
插了店铺名,永远匹配不到⇒同店互斥被写成任务失败。
护栏:后端 notification 六支用例(含 MaixiangConsoleClientTest 15 例、
MaixiangAnomalyScannerTest 24 例)、前端 dispatch-guard 与 enqueue-rejection-wiring 两支;
后端全量 3827 例 0 红、前端 717 例 0 失败;变异 M1-M7、M12-M14 共 10/10 杀。
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
||||
collectDistinctErrors,
|
||||
extensionOf,
|
||||
findUnsafeJsonPaths,
|
||||
classifyQueueRejection,
|
||||
shouldDeferQueuePush,
|
||||
guardPassed,
|
||||
type GuardResult,
|
||||
} from '../src/shared/dispatch-guard.ts'
|
||||
@@ -490,3 +492,38 @@ test('test_task_101_dispatch_guard_dependency_failure_does_not_throw', () => {
|
||||
// 修好之后同一入口可以继续用,说明模块没有内部状态残留
|
||||
assert.equal(checkParseResult({ taskId: 1, totalRows: 5, acceptedRows: 5 }).ok, true)
|
||||
})
|
||||
|
||||
// ------------------------------------------------------------ 队列拒绝分类
|
||||
|
||||
test('test_queue_rejection_shop_busy_is_caught_even_with_shop_name_inside_message', () => {
|
||||
// 互斥文案把店铺名插在「当前店铺」和「正在执行中」中间(app_client/main.py enqueue_json),
|
||||
// 旧页面用 includes('当前店铺正在执行中') 判互斥,带店名时永远匹配不到 ⇒ 同店互斥被写成任务失败。
|
||||
const legacy = classifyQueueRejection({ error: '当前店铺 鲍丽明-US 正在执行中,请等待店铺完成之后重试' })
|
||||
assert.equal(legacy.kind, 'shop_busy')
|
||||
assert.equal(legacy.deferrable, true)
|
||||
// 新版客户端直接给机器码,判定不再依赖中文文案
|
||||
assert.equal(classifyQueueRejection({ code: 'shop_busy', error: '文案随版本改' }).kind, 'shop_busy')
|
||||
})
|
||||
|
||||
test('test_queue_rejection_queue_full_is_deferrable_but_real_failures_are_not', () => {
|
||||
assert.equal(classifyQueueRejection({ code: 'queue_full' }).kind, 'queue_full')
|
||||
assert.equal(classifyQueueRejection({ code: 'queue_full' }).deferrable, true)
|
||||
assert.equal(classifyQueueRejection({ error: '任务队列已满(上限 50),请等待正在执行的任务完成后再提交' }).deferrable, true)
|
||||
// 数据本身不对:重试没有意义,必须照旧落失败并给出原因
|
||||
assert.equal(classifyQueueRejection({ error: '仅支持 JSON 对象或数组' }).kind, 'other')
|
||||
assert.equal(classifyQueueRejection({ error: '仅支持 JSON 对象或数组' }).deferrable, false)
|
||||
assert.equal(classifyQueueRejection({ code: 'parse_error', error: 'Excel 解析失败' }).deferrable, false)
|
||||
assert.equal(classifyQueueRejection(null).kind, 'other')
|
||||
assert.equal(classifyQueueRejection(undefined).deferrable, false)
|
||||
})
|
||||
|
||||
test('test_queue_deferral_budget_decision', () => {
|
||||
const busy = classifyQueueRejection({ code: 'shop_busy' })
|
||||
const hard = classifyQueueRejection({ code: 'parse_error', error: 'Excel 解析失败' })
|
||||
// 可以等 + 还没用尽预算才重试;两者任缺其一都落回「按失败收尾」
|
||||
assert.equal(shouldDeferQueuePush(busy, 0, 10), true)
|
||||
assert.equal(shouldDeferQueuePush(busy, 9, 10), true)
|
||||
assert.equal(shouldDeferQueuePush(busy, 10, 10), false, '预算用尽不得再等')
|
||||
assert.equal(shouldDeferQueuePush(hard, 0, 10), false, '真失败没有重试一说')
|
||||
assert.equal(shouldDeferQueuePush(busy, 0, 0), false)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
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'
|
||||
|
||||
/**
|
||||
* 入队被拒后的收尾接线(A4 同店互斥不再被写成任务失败)。
|
||||
*
|
||||
* 判定逻辑本体在 src/shared/dispatch-guard.ts,那边有真单元测试;这里钉两个组件里的
|
||||
* 接线——.vue 组件无法在本套里挂载,只能按源码形状钉(readSource 约定)。
|
||||
* 要防的回归形状只有一个:把「等一会儿再推」的分支删掉,回到 success=false 就
|
||||
* markPriceTrackDispatchFailed(→FAILED + 扣次数不回 + 通知面多一条任务失败)。
|
||||
*/
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const priceTrack = readFileSync(resolve(here, '../src/pages/brand/components/BrandPriceTrackTab.vue'), 'utf8')
|
||||
const deleteBrand = readFileSync(resolve(here, '../src/pages/brand/components/BrandDeleteBrandTab.vue'), 'utf8')
|
||||
|
||||
function bodyOf(source: string, startMarker: string, endMarker: string, label: string) {
|
||||
const start = source.indexOf(startMarker)
|
||||
assert.notEqual(start, -1, `${label} 里找不到 ${startMarker}`)
|
||||
const end = source.indexOf(endMarker, start)
|
||||
assert.notEqual(end, -1, `${label} 里找不到 ${endMarker}`)
|
||||
return source.slice(start, end)
|
||||
}
|
||||
|
||||
test('price_track_enqueue_defers_shop_busy_before_marking_failed', () => {
|
||||
const fn = bodyOf(
|
||||
priceTrack,
|
||||
'async function enqueueCreatedTask',
|
||||
'async function compensateDispatchFailure',
|
||||
'BrandPriceTrackTab.vue',
|
||||
)
|
||||
assert.match(fn, /classifyQueueRejection\(pushResult\)/, '没有对拒绝原因分类就直接收尾')
|
||||
assert.match(fn, /shouldDeferQueuePush\(rejection, attempt, /, '没有重试预算判定')
|
||||
const deferStart = fn.indexOf('shouldDeferQueuePush')
|
||||
const sleepAt = fn.indexOf('await sleep(', deferStart)
|
||||
assert.notEqual(sleepAt, -1, '可等待分支没有真的等')
|
||||
assert.notEqual(fn.indexOf('compensateDispatchFailure', sleepAt), -1, '预算用尽后仍应落失败并带上原因')
|
||||
// 等待分支必须自己回到循环,不能"等完还是判失败"——那等于把误判推迟一轮
|
||||
assert.doesNotMatch(fn.slice(deferStart, sleepAt), /compensateDispatchFailure/, '可等待分支不该直接收尾')
|
||||
assert.match(fn, /while \(true\)/, '重试要回到同一个推送入口')
|
||||
})
|
||||
|
||||
test('price_track_still_compensates_hard_failures', () => {
|
||||
// 反向钉:数据校验没过、桥调用抛异常、以及"不可等待/预算用尽"这三类都要照旧落失败带原因,
|
||||
// 别把「不再误判互斥」做成「什么都不判失败」。
|
||||
const fn = bodyOf(
|
||||
priceTrack,
|
||||
'async function enqueueCreatedTask',
|
||||
'async function compensateDispatchFailure',
|
||||
'BrandPriceTrackTab.vue',
|
||||
)
|
||||
assert.match(fn, /passGuard\(guard\)/, '入队前的数据闸还在')
|
||||
assert.match(fn, /catch \(error\)[\s\S]{0,240}compensateDispatchFailure\(taskId, reason\)/,
|
||||
'桥调用异常仍须立即落失败')
|
||||
assert.equal((fn.match(/compensateDispatchFailure\(taskId, reason\)/g) || []).length, 3,
|
||||
'三处收尾:数据闸 / 桥异常 / 拒绝且不可等待')
|
||||
})
|
||||
|
||||
test('delete_brand_tab_uses_the_shared_classifier', () => {
|
||||
// 旧写法 includes('当前店铺正在执行中') 匹配不到带店名的文案(客户端两个互斥出口都带名),
|
||||
// 自动续跑的"重试"闸因此从未生效过。
|
||||
assert.doesNotMatch(deleteBrand, /includes\('当前店铺正在执行中'\)/, '仍在用匹配不到的中文串判互斥')
|
||||
assert.doesNotMatch(deleteBrand, /function isQueueBusyError/, '旧判定函数应随之删除,别留死代码')
|
||||
assert.match(deleteBrand, /classifyQueueRejection\(pushResult\)/, '没有改用共享分类器')
|
||||
})
|
||||
|
||||
test('both_tabs_import_the_classifier', () => {
|
||||
for (const [name, src] of [['BrandPriceTrackTab.vue', priceTrack], ['BrandDeleteBrandTab.vue', deleteBrand]] as const) {
|
||||
assert.match(src, /classifyQueueRejection/, `${name} 未引用分类器`)
|
||||
assert.match(src, /from '@\/shared\/dispatch-guard'/, `${name} 未从 dispatch-guard 导入`)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user