修复:保护平台订单原始事实不被清理和覆盖
This commit is contained in:
@@ -6,21 +6,25 @@ async function readJobSource() {
|
||||
return readFile(new URL('./data-retention-job.ts', import.meta.url), 'utf8')
|
||||
}
|
||||
|
||||
test('保留清理必须覆盖 work_order_events,否则这张只增不减的表会一直拖慢历史单检索', async () => {
|
||||
test('数据维护不得覆盖原始报文或删除永久业务事实', async () => {
|
||||
const src = await readJobSource()
|
||||
assert.ok(
|
||||
src.includes("deleteOldRowsInBatches('work_order_events'"),
|
||||
'work_order_events 未纳入保留清理(生产上 71 万行 / 269MB 且只增不减)',
|
||||
)
|
||||
assert.ok(
|
||||
src.includes("'task_events' | 'webhook_events' | 'admin_audit_logs' | 'work_order_events'"),
|
||||
'删除助手需要显式允许 work_order_events(表名是白名单联合类型,避免拼接注入)',
|
||||
)
|
||||
assert.ok(src.includes('retention.workOrderEventDays'), '保留天数必须走配置项,便于按环境调整')
|
||||
assert.ok(
|
||||
src.includes('workOrderEventRows: number') && src.includes('workOrderEventRows,'),
|
||||
'清理结果要带上工单事件的删除行数,方便定时任务面板核对',
|
||||
)
|
||||
assert.equal(src.includes('raw_payload_json ='), false)
|
||||
assert.equal(src.includes('DELETE FROM'), false)
|
||||
for (const table of [
|
||||
'orders',
|
||||
'kuaishou_industry_vouchers',
|
||||
'task_events',
|
||||
'webhook_events',
|
||||
'admin_audit_logs',
|
||||
'work_order_events',
|
||||
]) {
|
||||
assert.equal(
|
||||
new RegExp(`(?:UPDATE|DELETE)\\s+${table}\\b`, 'i').test(src),
|
||||
false,
|
||||
`${table} 属于永久业务事实,不能在维护任务中清理或覆盖`,
|
||||
)
|
||||
}
|
||||
assert.ok(src.includes('永久业务事实未清理'))
|
||||
})
|
||||
|
||||
test('成本异常只归档已处理的行,open 队列不能被藏起来', async () => {
|
||||
@@ -64,29 +68,28 @@ test('保留任务要回填漏写的付款派生列,并在有命中时打日
|
||||
)
|
||||
})
|
||||
|
||||
test('保留清理默认窗口:敏感报文/事件 180 天,审计 365 天,工单事件 180 天', async () => {
|
||||
test('数据维护只保留可派生数据的成本异常归档窗口', async () => {
|
||||
const defaults = await readFile(new URL('../../config/defaults.ts', import.meta.url), 'utf8')
|
||||
assert.ok(defaults.includes('costExceptionDays: 60'))
|
||||
for (const line of [
|
||||
'rawPayloadDays: 180',
|
||||
'taskEventDays: 180',
|
||||
'webhookEventDays: 180',
|
||||
'auditLogDays: 365',
|
||||
'workOrderEventDays: 180',
|
||||
'costExceptionDays: 60',
|
||||
'rawPayloadDays:',
|
||||
'taskEventDays:',
|
||||
'webhookEventDays:',
|
||||
'auditLogDays:',
|
||||
'workOrderEventDays:',
|
||||
]) {
|
||||
assert.ok(defaults.includes(line), `默认保留策略缺少 ${line}`)
|
||||
assert.equal(defaults.includes(line), false, `永久事实不能存在清理窗口 ${line}`)
|
||||
}
|
||||
|
||||
const overrides = await readFile(
|
||||
new URL('../../config/env-overrides.ts', import.meta.url),
|
||||
'utf8',
|
||||
)
|
||||
assert.ok(
|
||||
overrides.includes(
|
||||
"integerEnv('WORK_ORDER_EVENT_RETENTION_DAYS', ['retention', 'workOrderEventDays'])",
|
||||
),
|
||||
'WORK_ORDER_EVENT_RETENTION_DAYS 需要环境变量出口,否则生产无法调整',
|
||||
)
|
||||
assert.equal(overrides.includes('RAW_PAYLOAD_RETENTION_DAYS'), false)
|
||||
assert.equal(overrides.includes('TASK_EVENT_RETENTION_DAYS'), false)
|
||||
assert.equal(overrides.includes('WEBHOOK_EVENT_RETENTION_DAYS'), false)
|
||||
assert.equal(overrides.includes('AUDIT_LOG_RETENTION_DAYS'), false)
|
||||
assert.equal(overrides.includes('WORK_ORDER_EVENT_RETENTION_DAYS'), false)
|
||||
assert.ok(
|
||||
overrides.includes(
|
||||
"integerEnv('COST_EXCEPTION_RETENTION_DAYS', ['retention', 'costExceptionDays'])",
|
||||
|
||||
Reference in New Issue
Block a user