- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14) - T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9) - T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4) - T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8) - T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15) - T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8) - T7 前后端测试与 lint 门禁清零 - T8 应付卡片按关联订单日(口径 A) - T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
99 lines
4.8 KiB
TypeScript
99 lines
4.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
|
||
import { needsAppendToOrder } from '../src/services/mainSystemOrderImport';
|
||
|
||
/**
|
||
* **主系统分配了、我方订单里却没有那一行** 的回归(2026-10-13 真库事故:
|
||
* BR003「米块」prep `2f8564f6…` —— 主系统一直分配着、我方订单
|
||
* `ORD_API_20261012_BR003_0002` 里永远没有它)。
|
||
*
|
||
* 根因两层(都已修):
|
||
* ① 源头:`recordImportedPrepItems` 只看"行在不在主系统 active 列表",**不看有没有配上我方订单行**
|
||
* ⇒ 配不上的行也被写成 `disposition='imported'`;
|
||
* ② 判据:`needsAppendToOrder` 只重试 `pending`/`skipped_stockout` ⇒ `imported` + 空链接**永久卡死**。
|
||
*
|
||
* 现在:源头配不上就写 `pending`(可重试);判据把"链接为空"一律视为要补(只排除人工/业务终态);
|
||
* 并每轮导入做一次**一致性巡检**把这种自相矛盾态打成告警。
|
||
*/
|
||
|
||
const importSrc = readFileSync(
|
||
path.join(__dirname, '../src/services/mainSystemOrderImport.ts'),
|
||
'utf8'
|
||
);
|
||
const ledgerSrc = readFileSync(
|
||
path.join(__dirname, '../src/services/mainSystemPrepLedger.ts'),
|
||
'utf8'
|
||
);
|
||
|
||
const PREP = '2f8564f6-da45-43f1-b074-2457bfe08672';
|
||
|
||
function ledgerRow(overrides: Partial<{ prep_id: string; our_order_item_id: string | null; disposition: string | null }> = {}) {
|
||
return { prep_id: PREP, our_order_item_id: null as string | null, disposition: 'imported' as string | null, ...overrides };
|
||
}
|
||
|
||
describe('追加判据:台账 ↔ 我方订单行的唯一闸门', () => {
|
||
it('① 台账里没有这一行(主系统后来才分配)⇒ 要补', () => {
|
||
expect(needsAppendToOrder({ id: PREP }, [])).toBe(true);
|
||
expect(needsAppendToOrder({ id: PREP }, undefined)).toBe(true);
|
||
});
|
||
|
||
it('② 已配上我方订单行 ⇒ 不补(幂等,不重复加行)', () => {
|
||
expect(needsAppendToOrder({ id: PREP }, [ledgerRow({ our_order_item_id: 'item-1' })])).toBe(false);
|
||
});
|
||
|
||
it('③ **回归**:`imported` + 链接为空 ⇒ 要补(旧实现在这里永久卡死)', () => {
|
||
expect(needsAppendToOrder({ id: PREP }, [ledgerRow({ disposition: 'imported' })])).toBe(true);
|
||
});
|
||
|
||
it('④ 其它非终态处置 + 链接为空 ⇒ 也要补(pending / skipped_stockout / 未知值兜底)', () => {
|
||
for (const disposition of ['pending', 'skipped_stockout', 'weird_future_value', null]) {
|
||
expect(needsAppendToOrder({ id: PREP }, [ledgerRow({ disposition })])).toBe(true);
|
||
}
|
||
});
|
||
|
||
it('⑤ 人工/业务终态 ⇒ 不自动补(cancelled / returned / completed / suspended)', () => {
|
||
for (const disposition of ['cancelled', 'returned', 'completed', 'suspended']) {
|
||
expect(needsAppendToOrder({ id: PREP }, [ledgerRow({ disposition })])).toBe(false);
|
||
}
|
||
});
|
||
|
||
it('⑥ 主系统说这行缺货(isStockout)⇒ 不补', () => {
|
||
expect(needsAppendToOrder({ id: PREP, isStockout: true }, [])).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe('源头:配不上订单行就不许写 imported(源码钉)', () => {
|
||
it('① disposition 必须依赖 mapping(配不上 ⇒ pending,可重试)', () => {
|
||
expect(ledgerSrc).toContain("isStockoutRow(row) ? 'skipped_stockout' : mapping.get(prepId) ? 'imported' : 'pending'");
|
||
});
|
||
|
||
it('② 判据不再用旧的"只重试 pending/skipped_stockout"白名单', () => {
|
||
expect(importSrc).not.toContain('APPEND_RETRYABLE_DISPOSITIONS');
|
||
// 2026-10-19 T2/BIZ-9:常量改为多行并加入 removed(删行硬删阻断);reallocated 可复活不得列入。
|
||
const blockedStart = importSrc.indexOf('const APPEND_BLOCKED_DISPOSITIONS');
|
||
expect(blockedStart).toBeGreaterThan(-1);
|
||
const blockedSet = importSrc.slice(blockedStart, importSrc.indexOf(']);', blockedStart));
|
||
for (const disposition of ['cancelled', 'returned', 'completed', 'suspended', 'removed']) {
|
||
expect(blockedSet, `终态 ${disposition} 必须继续阻断追加`).toContain(`'${disposition}'`);
|
||
}
|
||
expect(blockedSet).not.toContain("'reallocated'");
|
||
});
|
||
});
|
||
|
||
describe('防复发:每轮导入做一次一致性巡检(自相矛盾态必须可见)', () => {
|
||
it('① 巡检函数存在,且查的是 imported + 空链接', () => {
|
||
expect(importSrc).toContain('export async function auditUnlinkedImportedRows');
|
||
expect(importSrc).toMatch(/disposition = 'imported'/);
|
||
expect(importSrc).toMatch(/our_order_item_id IS NULL/);
|
||
});
|
||
|
||
it('② 导入主入口(webhook 与定时对账共用)每轮都调用它,且失败不影响导入', () => {
|
||
const at = importSrc.indexOf('export async function importMainSystemOrders(');
|
||
const body = importSrc.slice(at, at + 1600);
|
||
expect(body).toContain('await auditUnlinkedImportedRows(branchCode)');
|
||
expect(body).toContain('不影响导入');
|
||
});
|
||
});
|