Files
SupplierSystem/server/tests/mainSystemClientContract.test.ts
Ubuntu aa2db57b0f
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
feat(main-system): 免入库单取货链路 + 实收数量「事实登记 + 事后同步」
免入库(主系统骑手上门取货):
- 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 双端干净
2026-10-09 21:52:17 +08:00

92 lines
4.0 KiB
TypeScript
Raw Permalink 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 { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
/**
* 主系统对接模块的**两条契约**(开发者 2026-10-11 要求):
* ① **域名单一来源**:所有端点 URL 都由 `MAIN_SYSTEM_BASE_URL` 派生,
* 换域名/换路径只改 env(或 `MAIN_SYSTEM_*_PATH`),业务代码里没有第二份地址;
* ② **默认关**:未设 `MAIN_SYSTEM_PRICE_QTY_ENABLED=1` 时,跨系统改价/改量整条链路关闭
* ⇒ 正常下单/改明细路径零影响(与改造前逐字节一致)。
*/
const saved = {
baseUrl: process.env.MAIN_SYSTEM_BASE_URL,
priceQty: process.env.MAIN_SYSTEM_PRICE_QTY_ENABLED,
requestPath: process.env.MAIN_SYSTEM_PRICE_QTY_REQUEST_PATH,
};
function restoreEnv() {
for (const [key, value] of Object.entries({
MAIN_SYSTEM_BASE_URL: saved.baseUrl,
MAIN_SYSTEM_PRICE_QTY_ENABLED: saved.priceQty,
MAIN_SYSTEM_PRICE_QTY_REQUEST_PATH: saved.requestPath,
})) {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
}
beforeEach(() => {
vi.resetModules();
});
afterEach(() => {
restoreEnv();
vi.resetModules();
});
describe('主系统域名 / 端点:单一来源', () => {
it('改 MAIN_SYSTEM_BASE_URL 即改所有端点(含尾斜杠归一)', async () => {
process.env.MAIN_SYSTEM_BASE_URL = 'https://main.example.com/erp/';
vi.resetModules();
const { buildMainSystemUrl } = await import('../src/services/mainSystem/endpoints');
expect(buildMainSystemUrl('preparations')).toBe('https://main.example.com/erp/api/supplier/preparations');
expect(buildMainSystemUrl('preparationsStatus')).toBe(
'https://main.example.com/erp/api/supplier/preparations/status'
);
expect(buildMainSystemUrl('priceQtyRequest')).toBe(
'https://main.example.com/erp/api/supplier/preparations/price-qty-request'
);
expect(buildMainSystemUrl('preparations', { view: 'price_amend' })).toBe(
'https://main.example.com/erp/api/supplier/preparations?view=price_amend'
);
});
it('端点路径可被 env 覆盖(主系统改路径时不用改代码)', async () => {
process.env.MAIN_SYSTEM_BASE_URL = 'http://127.0.0.1:3001';
process.env.MAIN_SYSTEM_PRICE_QTY_REQUEST_PATH = '/api/supplier/v2/price-qty-request';
vi.resetModules();
const { buildMainSystemUrl } = await import('../src/services/mainSystem/endpoints');
expect(buildMainSystemUrl('priceQtyRequest')).toBe(
'http://127.0.0.1:3001/api/supplier/v2/price-qty-request'
);
});
it('域名为空时抛错而不是拼出奇怪地址', async () => {
// 注意:`src/config.ts` 在 import 时会 `loadEnv()` 回读 `server/.env`(且不覆盖已存在的 env),
// 所以这里用**空串**表达"未配置",而不是 delete(delete 会被回读补回来)。
process.env.MAIN_SYSTEM_BASE_URL = '';
vi.resetModules();
const { buildMainSystemUrl } = await import('../src/services/mainSystem/endpoints');
expect(() => buildMainSystemUrl('preparations')).toThrow(/MAIN_SYSTEM_BASE_URL/);
});
});
describe('跨系统改价/改量:开关判定(`=1` 才开,其余一律关)', () => {
// ⚠️ 不能用 delete 表达"未配置":`src/config.ts` 在 import 时会 `loadEnv()` 回读 `server/.env`
// (且不覆盖已存在的 env)⇒ delete 会被回读补回来。用**空串/其它值**表达"关",
// 这样本地 `.env` 里联调把开关置 1 时,本用例仍然稳定。
it('空串 / 0 / true 都当关;只有 =1 才算开', async () => {
for (const value of ['', '0', 'true', 'yes']) {
process.env.MAIN_SYSTEM_PRICE_QTY_ENABLED = value;
vi.resetModules();
const config = await import('../src/services/mainSystem/config');
expect(config.isPriceQtyRequestEnabled(), `值 "${value}" 应为关`).toBe(false);
}
process.env.MAIN_SYSTEM_PRICE_QTY_ENABLED = '1';
vi.resetModules();
const on = await import('../src/services/mainSystem/config');
expect(on.isPriceQtyRequestEnabled()).toBe(true);
});
});