Files
SupplierSystem/server/tests/importSelfPurchaseMissingPurchaser.contract.test.ts
Ubuntu 06233ff0b0
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(进销存/自采): 部分抵扣缺口默认自采同样在无采购员时按自由池建单
上一提交(59dcfd5)修的是「主系统导入单无抵扣 ⇒ 默认自采」入口;代码复查发现**同类的第二个入口**:
`ensureSelfPurchaseForCoverGap`(库存部分抵扣后的缺口默认自采,在 reprocessOrderAllocation 内,
导入单提交也会经过)仍调用 createPurchaseOrderForItem 不传 allowMissingPurchaser ⇒ 分公司无采购员时
每行静默返回 false,而 `STOCK_COVER_SUPPLIER_SQL` 已把行标 INTERNAL ⇒ 同样留下
「界面自采、自采表无数据、订单卡 20 待分配」的半成品(与刚修复的事故同类,尚未在真机触发)。

修复:该入口也传 allowMissingPurchaser: true(无采购员按自由池建单);并在
「有行需转自采但 created=0」时打 warn(原先完全静默)。
验证:契约测试 4/4(新增部分抵扣分支断言);typecheck 通过;后端全量 3 failed / 579 passed
(18 failed / 4145 passed,红均为既有 mainSystemReturnCancel/opsGuardHardening/routeLayerBoundary)。
设计文档同步两处入口。未部署。
2026-10-22 15:13:25 +08:00

47 lines
2.3 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 主系统导入单「无抵扣默认自采」:分公司没有可用采购员时按自由池建自采单。
*
* 真机事故(2026-10-22 体验账号 BR003):行被标成 INTERNAL(自采),但
* createPurchaseOrderForItem 因"无可用采购员"静默 return false ⇒ 自采表 0 行,
* 订单永远卡在 20 待分配(状态提示"尚有未履约明细…请先分配供应商或转自采")。
*/
describe('导入单默认自采:无采购员按自由池建单(不静默卡单)', () => {
const service = readFileSync(
new URL('../src/services/orderAllocationService.ts', import.meta.url),
'utf8'
);
it('createPurchaseOrderForItem 支持 allowMissingPurchaser,且未开启时保持旧行为', () => {
expect(service).toContain('allowMissingPurchaser?: boolean');
expect(service).toContain('if (params.allowMissingPurchaser) {');
expect(service).toContain('free_pool');
// 未开启分支仍 return false(其它分配路径行为不变)
expect(service).toContain('} else {\n return false;\n }');
});
it('ensureSelfPurchaseForImportedOrder 传入 allowMissingPurchaser(仅该导入口径)', () => {
expect(service).toContain('allowMissingPurchaser: true');
// 传参位置必须在 ensureSelfPurchaseForImportedOrder 内
const fnStart = service.indexOf('export async function ensureSelfPurchaseForImportedOrder');
expect(fnStart).toBeGreaterThan(0);
// 函数较长(含内部 SQL/接口),取后续 8000 字符覆盖完整函数体
const body = service.slice(fnStart, fnStart + 8000);
expect(body).toContain('allowMissingPurchaser: true');
});
it('部分抵扣缺口默认自采分支同样传 allowMissingPurchaser(同一类半成品)', () => {
const gapStart = service.indexOf('async function ensureSelfPurchaseForCoverGap');
expect(gapStart).toBeGreaterThan(0);
const body = service.slice(gapStart, gapStart + 6000);
expect(body).toContain('allowMissingPurchaser: true');
expect(body).toContain('部分抵扣缺口 ${attempted} 行需转自采但一张采购单未建');
});
it('行命中却一张没建时留 warn(不再完全静默)', () => {
expect(service).toContain('标记自采 ${rows.rowCount} 行但未建任何采购单');
});
});