Files
SupplierSystem/server/tests/independentInboundIsolation.test.ts
T
Ubuntu b1b3f9c455
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
test(独立进货): 隔离性回归 —— 钉死"不影响正常客户下单流程"
开发者 2026-10-12:「可以这样,但是不能影响选择了正常客户的下单流程」。

真库冒烟对照(BR003,正常客户 MAIN_BR002,可乐 4 瓶 × 销售价 2.5 / 成本价 12):
  price 2.50 / amount 10.00 / 订单头 total_amount 10.00 / unit_cost 12 / needs_customer_price=false
  ⇒ 与改动前一致,**没有被"独立进货锁 0"污染**(冒烟单用后即移入垃圾桶)。

新增 server/tests/independentInboundIsolation.test.ts(10 例)逐条钉住"正常分支表达式未变":
  · 录单:售价/金额、订单头金额、needs_customer_price/price_source、零价提交闸门、信用校验、
    客户×商品映射学习 —— 全部是 `哨兵 ? ... : 原表达式` 形态;
  · 分配/结案零价守卫:正常单仍由 `options.allowUnpriced` 决定;
  · 结案状态白名单:普通单仍只允许 30/50(40 只对哨兵开);
  · 完成推进:哨兵分支提前 return,正常链路顺序与调用未改;
  · 销售谓词用 IS DISTINCT FROM(NULL 安全)⇒ 只有哨兵单被排除,
    明确禁止写成 `<>`(否则 customer_code IS NULL 的历史单会被三值逻辑漏掉)。
2026-10-12 19:18:32 +08:00

88 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { readFileSync } from 'node:fs';
import path from 'node:path';
/**
* **隔离性回归**(开发者 2026-10-12:「可以这样,但是不能影响选择了正常客户的下单流程」)。
*
* 「独立进货」的每条改动都必须是**哨兵单专用分支** —— 正常客户走的仍是原来那句表达式。
* 这里逐条钉住"正常分支没被改写",并用真库冒烟对照过:
* 普通客户录单(MAIN_BR002,可乐 4 瓶 × 2.5,成本 12)⇒ price 2.50 / amount 10.00 /
* 订单头 10.00 / needs_customer_price=false(若被"锁 0"污染就会变 0)。
*/
const svc = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8');
const submit = svc('src/services/customerOrderSubmitService.ts');
const fulfill = svc('src/services/orderWorkflowFulfillmentService.ts');
const alloc = svc('src/services/orderAllocationService.ts');
const dashboard = svc('src/services/dashboardService.ts');
const sentinel = svc('src/services/independentInbound.ts');
describe('录单提交:哨兵分支与正常分支共存,正常分支表达式未变', () => {
it('① 销售价/金额:只有哨兵单写 0,正常客户照用传入价', () => {
expect(submit).toContain('const revenuePrice = independentInbound ? 0 : price;');
expect(submit).toContain('const revenueAmount = independentInbound ? 0 : amount;');
});
it('② 订单头金额:只有哨兵单为 0', () => {
expect(submit).toContain('totalAmount: isIndependentInboundCustomer(input.customerCode) ? 0 : estimatedAmount');
});
it('③ 需求价标记:正常客户仍按原判据(price<=0 ⇒ needs_customer_price / missing)', () => {
expect(submit).toContain(
'independentInbound ? false : price <= 0 ? true : (item.needs_customer_price ?? false)'
);
expect(submit).toContain(
"independentInbound ? 'independent_inbound' : price <= 0 ? 'missing' : (item.price_source ?? null)"
);
});
it('④ 零价提交闸门:正常客户仍由分公司开关决定', () => {
expect(submit).toContain('input.allowUnpriced === true || independentInboundOrder');
expect(submit).toContain('await isBlockZeroSaleOnSubmitEnabled(input.branchCode)');
});
it('⑤ 信用校验:正常客户仍走 assertCustomerCredit;只有哨兵短路', () => {
const idx = submit.indexOf('const credit = isIndependentInboundCustomer(input.customerCode)');
expect(idx).toBeGreaterThan(-1);
expect(submit.slice(idx, idx + 600)).toContain('await assertCustomerCredit(input.customerCode, estimatedAmount)');
});
it('⑥ 客户×商品映射学习:正常客户照常同步', () => {
expect(submit).toContain('await syncCustomerMappings({');
});
it('⑦ 分配口零价守卫:正常单仍是 options.allowUnpriced 说了算', () => {
expect(alloc).toContain('options.allowUnpriced === true || (await isOrderIndependentInbound(orderCode, client))');
expect(fulfill).toContain('options?.allowUnpriced === true || (await isOrderIndependentInbound(orderCode, db))');
});
});
describe('状态机:哨兵分支提前 return,正常单链路一字未改', () => {
it('① 结案状态白名单:普通单仍只允许 30/50(40 只对哨兵开)', () => {
const idx = fulfill.indexOf('const fromInspectionForIndependentInbound');
expect(idx).toBeGreaterThan(-1);
expect(fulfill.slice(idx, idx + 260)).toContain(
'status === 40 && (await isOrderIndependentInbound(orderCode, db))'
);
expect(fulfill).toContain('if (status !== 30 && status !== 50 && !fromInspectionForIndependentInbound)');
});
it('② 完成推进:哨兵分支在正常链路之前且自带 return', () => {
const src = svc('src/services/processingTaskService.ts');
const idx = src.indexOf('if (await isOrderIndependentInbound(orderCode, pool))');
expect(idx).toBeGreaterThan(-1);
const body = src.slice(idx, idx + 600);
expect(body).toContain('return {');
expect(idx).toBeLessThan(src.indexOf('const pickingEnabled = await isPickingWorkflowEnabled'));
});
});
describe('销售口径谓词:对正常客户(含 customer_code 为空的历史单)必须为真', () => {
it('用 IS DISTINCT FROM(NULL 安全)⇒ 只有哨兵单被排除', () => {
expect(sentinel).toContain("customer_code IS DISTINCT FROM '${INDEPENDENT_INBOUND_CUSTOMER_CODE}'");
// 不得写成 `<>`:那样 customer_code IS NULL 的行会被 SQL 三值逻辑悄悄漏掉
expect(sentinel).not.toMatch(/customer_code\s*<>/);
expect(dashboard).toContain('salesVisibleOrderSql');
});
});