免入库(主系统骑手上门取货): - 50 展示「待取货」、副文案「待主系统骑手上门取货」、不建我方配送任务(守卫与开关解耦) - 我方 50 即回写备货完成;两开关(SKIP_INBOUND_AWAIT_PICKUP / FULFILLMENT_EVENTS)改默认开 核货事实镜像(「核货完毕」标记): - 按主系统 lookup 的 actual_qty 落台账,新增 GET/POST /orders/:orderCode/main-system-prep-facts[/refresh] - 详情行内显示「核货完毕」(含核货量),分配对账兜底刷新 实收数量/单位口径变更(对方先改 + 我方事后同步): - 台账加 applied_at;inbound 与 picking_check 同为事实登记(驳回不回滚) - 同意才落我方值:免入库改装车核货量、送仓改验收实收(已入库走既有库存调整)、已结算/已结案只留痕 - 计划量与金额一起改,并同步结算投影(syncStatementsForOrderSafe) - 审核页语义改「主系统实际值(已生效)/ 是否同步」+ 已处理历史(双方时间与落值结论) 台账对照与回写修复: - 行级对照改整单一次性(同名商品不再重复认领)+ 存量纠正 healOrderPrepMapping - 堵住客户绑定回填旁路(免入库单不再被派我方骑手) - 回写触发函数改对象参数(修 branch/order 传反导致的静默不回写) 文档:设计文档 4 篇 +《给主系统 AI 的对接改造清单》§2.9(第六批契约) 回归:服务端全量与 HEAD 基线一致(24 个失败文件同集合);前端 140 文件 / 699 测试全绿;tsc 双端干净
76 lines
3.6 KiB
TypeScript
76 lines
3.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
|
||
/**
|
||
* 主系统「核货完毕」事实镜像(2026-10-11,设计文档 `20261011-免入库核货完毕标记.md`)。
|
||
*
|
||
* 钉住四件事:
|
||
* ① 事实只来自**拉取**(事件通道对"等量核货"静默)——lookup 是唯一可靠通道;
|
||
* ② 落库只覆盖 payload 的 5 个事实键,**不得**顺手改其它键(台账 payload 是共享快照);
|
||
* ③ 判定口径是 `actualQty != null` 且**仅免入库行**(送仓行已有"入库完成"标签);
|
||
* ④ GET 路由**不调外部**(主系统抖动不得拖垮详情),刷新是独立 POST 且失败不 500。
|
||
*/
|
||
const service = readFileSync(
|
||
path.join(__dirname, '../src/services/mainSystemActualFacts.ts'),
|
||
'utf8'
|
||
);
|
||
const routes = readFileSync(
|
||
path.join(__dirname, '../src/modules/workflow/routes/orderRoutes.ts'),
|
||
'utf8'
|
||
);
|
||
const importLoop = readFileSync(path.join(__dirname, '../src/services/mainSystemOrderImport.ts'), 'utf8');
|
||
|
||
describe('核货事实:通道与落库', () => {
|
||
it('用 lookup 拉(不受 active/archived 视图影响),不靠事件', () => {
|
||
expect(service).toMatch(/lookupMainSystemPreparationStates/);
|
||
// 代码里**不得**出现事件订阅/收件箱依赖(`actual_qty_request` 只允许出现在解释性注释里)
|
||
const codeOnly = service
|
||
.split('\n')
|
||
.filter((line) => !line.trim().startsWith('*') && !line.trim().startsWith('//') && !line.trim().startsWith('/*'))
|
||
.join('\n');
|
||
expect(codeOnly).not.toMatch(/actual_qty_request/);
|
||
});
|
||
|
||
it('只覆盖 payload 的 5 个事实键(payload || jsonb_build_object)', () => {
|
||
expect(service).toMatch(/payload \|\| jsonb_build_object/);
|
||
for (const key of ['actualQty', 'actualQtyAt', 'qtyDiff', 'isInbounded', 'inboundAt']) {
|
||
expect(service, `缺少事实键 ${key}`).toContain(`'${key}'`);
|
||
}
|
||
// 不得整包替换 payload(那是导入的职责,会把 skipInbound 等事实抹掉)
|
||
expect(service).not.toMatch(/SET payload = \$/);
|
||
});
|
||
|
||
it('判定用 actualQty != null(不用 actualQtyAt:免入库行实测恒为 null)', () => {
|
||
expect(service).toMatch(/checked: actualQty !== null/);
|
||
expect(service).toMatch(/不用 `actualQtyAt`/);
|
||
});
|
||
});
|
||
|
||
describe('核货事实:路由与兜底', () => {
|
||
it('GET 路由只读库,POST 路由才拉取,两者都要权限', () => {
|
||
const getIdx = routes.indexOf("'/orders/:orderCode/main-system-prep-facts'");
|
||
const postIdx = routes.indexOf("'/orders/:orderCode/main-system-prep-facts/refresh'");
|
||
expect(getIdx).toBeGreaterThan(-1);
|
||
expect(postIdx).toBeGreaterThan(-1);
|
||
const getBlock = routes.slice(getIdx, getIdx + 900);
|
||
const postBlock = routes.slice(postIdx, postIdx + 1100);
|
||
expect(getBlock).toMatch(/listOrderActualFacts/);
|
||
expect(getBlock).not.toMatch(/refreshOrderActualFacts/);
|
||
expect(postBlock).toMatch(/refreshOrderActualFacts/);
|
||
expect(getBlock).toMatch(/requireWorkflowPermission/);
|
||
expect(postBlock).toMatch(/requireWorkflowPermission/);
|
||
});
|
||
|
||
it('刷新失败不抛(详情必须照常展示库内已有事实)', () => {
|
||
const idx = service.indexOf('export async function refreshOrderActualFacts');
|
||
const fn = service.slice(idx, idx + 900);
|
||
expect(fn).toMatch(/catch \(error: unknown\)/);
|
||
expect(fn).toMatch(/refreshed = false|reason =/);
|
||
});
|
||
|
||
it('定时对账里挂了在飞单兜底(等量核货没人打开详情也能补上)', () => {
|
||
expect(importLoop).toMatch(/refreshInFlightActualFactsForBranch/);
|
||
});
|
||
});
|