Files
SupplierSystem/server/tests/mainSystemQtyLock.test.ts
Ubuntu 6fb1616629
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(配送日): 补上「明细保存」通道的配送日锁 + 同步前后端文案(开发者 4 点决定)
开发者逐条决定:①两张不同配送日的单一律按当日(现有实现已满足,无需改);
②批准补锁但要求确保功能不出问题;③准时率不常用(不动);④文案先改、事后核查。

## ① 两张不同配送日的单 = 都按导入当日(已满足,未改代码)
每个导入批次都走 `createDayOrder` ⇒ 配送日 = `formatChinaDate()`。主系统 10-19 / 10-20 两批若今天导入,
我方两张单都是今天;去重/占坑键仍用主系统日期(两批不会撞成一个坑)。

## ② 补锁:改 `orders.delivery_date` 的第二条通道
原先 `main_system_delivery_date_locked` **只挂在行内单字段通道**(`updateOrderDeliveryDate`),
经「保存明细」(`syncOrderManageItems` 的 `orderPatch`)仍可改写、甚至清空主系统单配送日 ⇒ 口径可被绕过。
本轮补同款锁:
- 判据**逐字同源**(行级 `main_order_code` 非空 = 主系统分配行);
- ⚠️ **只在"配送日真的变了"时才拦** —— Web 保存明细会把当前值**原样回传**,无条件拦会把主系统单正常保存打挂;
  为此加载订单时补取 `delivery_date`(原 SELECT 没有该列,无法判断"变了没");
- 抛错在 `COMMIT` 之前、同一事务 ⇒ 外层 catch 回滚,**不写半截**。

## 真库功能验证(真实主系统单 ORD_API_20261016_BR002_0001,16 行)
- 改配送日(10-18 → 10-19)⇒ `409 main_system_delivery_date_locked`,
  订单 `delivery_date` / 金额 / 重量 / 16 行明细数量**逐字未变**(确认全量回滚);
- 同值保存(10-18 → 10-18)⇒ **未被拦**,数据未变(确认不误伤正常保存)。

## ④ 文案(zh/en/id 三语 + 后端两处提示语)
`list.deliveryDateLocked`:`分发订单的配送时间无法修改(以主系统为准)`
→ **`分发订单的配送时间由导入当日确定,无法修改`**(en/id 同步);后端行内单字段通道的 409 消息也一并同口径。

## 回归(重点:本轮先引入、后被自己抓出的 1 条)
补锁时改了 409 文案 ⇒ 既有 `tests/mainSystemQtyLock.test.ts` 的**文案断言**变红(该测试钉的是旧措辞)。
已把断言同步到新措辞(其余断言——错误码、判据、拦截顺序——一字未动),并新增契约测试 ⑤ 钉住
"两条通道同锁 + 只在值变化时拦 + 三语文案"。
**同条件对照(同 29 文件 + mainSystemQtyLock、同 .env)**:基线 f08792f = 36 条红,
本轮 = 36 条红,失败集合**逐条一致、无新增无减少**;`mainSystemQtyLock` 由红转绿。
定向:受影响 7 文件 108 通过;`mainSystemQtyLock` + 配送日契约测试 21 通过。
前端全量:3 文件 / 6 条红 = 与基线相同(既有红)。
类型:server 仅剩既有 `prompts/defaults.ts(465)`;web 0 错。门禁快档 8 通过 / check-ai-cost 既有红。

## ③ 准时率(未动,仅登记)
代码里确有看板「准时履约」统计,口径 = `orders.delivery_date + customers.delivery_time`
(`deliveryDeadlineSql.ts` / `dashboardService.ts`)。开发者说该功能一般不使用 ⇒ 本轮不改代码,
只在设计文如实登记"配送日提前 ⇒ 须送达时刻提前 ⇒ 该统计可能下降;新单生效、存量不变"。
2026-10-16 21:36:06 +08:00

152 lines
8.1 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 { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 主系统分配行的**数量不可改**(开发者 2026-10-10 口径):
* 「主系统给子系统的订单,这个**计划数量**取消可以编辑的权限(子系统正常录单的不要被影响)」。
*
* 三道门(缺一不可):
* ① 界面(Web 订单明细):计划数量渲染成文本 —— `orderDetailPlanQtyLock.test.ts`;
* ② 服务层(改明细 5 个入口共用):主系统分配行的 `quantity` 改动 **409 直接拒绝**(本文件);
* ③ 小程序(订单管理端 + 采购员端):明细接口带 `main_order_code`、数量格置灰不进编辑弹窗。
*
* 只锁**数量**:价格仍走「先改后通知」(2026-10-12 口径);我方自建行(加菜/自录)完全不受影响。
*/
const service = readFileSync(
new URL('../src/services/orderManageItemsService.ts', import.meta.url),
'utf8'
);
const mobileAdmin = readFileSync(
new URL('../src/routes/mobile/mobileAdminRoutes.ts', import.meta.url),
'utf8'
);
const mobilePurchaser = readFileSync(
new URL('../src/routes/mobile/mobilePurchaserOrderRoutes.ts', import.meta.url),
'utf8'
);
const mpJs = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.js', import.meta.url),
'utf8'
);
const mpWxml = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.wxml', import.meta.url),
'utf8'
);
describe('服务层:加工方式锁已解封(2026-10-14 开发者令),配送时间仍锁', () => {
it('加工方式/加工方**不再被拦**:旧 409 通道已删除(反向棘轮,防回归)', () => {
/**
* 2026-10-14 开发者:「这块需要解封 当前加工方式是自己设置了」。
* 口径来源 docs/design/20261014-主系统加工需求与我方加工决策.md §6.3 D2''、§7 验收 5:
* 主系统的 `processingMethod` 只作**提示**(并入行备注),加工方式由**我方**设置 ⇒
* 不能再拦(拦了只会拦住我们自己:详情页能改、保存却 409)。
*/
expect(service).not.toMatch(/code: 'main_system_processing_locked'/);
expect(service).not.toContain('分发订单的加工方式无法修改(以主系统为准)');
expect(service).not.toMatch(/function collectMainSystemProcessingChanges/);
expect(service).not.toContain('guardedProcessingChanges');
expect(service).not.toContain('if (changes.length || processingChanges.length) {');
// 留痕:解封原因写在服务层注释里(下次有人想加回这道门,先看这段)
expect(service).toContain('加工方式**已解封**');
});
it('配送时间改动 ⇒ 409 main_system_delivery_date_locked,判据=整单存在主系统分配行', () => {
const idx = service.indexOf('export async function updateOrderDeliveryDate');
expect(idx).toBeGreaterThan(-1);
const body = service.slice(idx, idx + 2600);
expect(body).toContain("code: 'main_system_delivery_date_locked'");
// 文案随口径更新(2026-10-16 开发者批准):配送日现在由「导入当日」决定,不再说"以主系统为准"
expect(body).toContain('分发订单的配送时间由导入当日确定,无法修改');
expect(body, '判据必须按行 main_order_code(与我方自建单区分)').toContain(
"NULLIF(TRIM(main_order_code), '') IS NOT NULL"
);
// 必须在状态闸门/更新之前拦下
expect(body.indexOf('main_system_delivery_date_locked')).toBeLessThan(
body.indexOf('canEditDeliveryDateByStatus')
);
});
});
describe('服务层:主系统分配行改数量 ⇒ 409(不是"先改后通知")', () => {
it('只拦 quantity、只拦 guarded(主系统分配行),错误码固定', () => {
const idx = service.indexOf("const qtyLocked = guardedChanges.filter");
expect(idx, '未找到数量拦住逻辑').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 1200);
expect(body).toContain("change.field === 'quantity'");
expect(body).toContain("code: 'main_system_qty_locked'");
// 文案与小程序一致(「分发订单的数量无法修改」),便于用户在两处看到同一句话
expect(body).toContain('分发订单的数量无法修改(${names})');
expect(body).toContain('status: 409');
// 抛错在"通知主系统"之前 ⇒ 被拒的改动不会既报错又发通知
const noticeIdx = service.indexOf('priceQtyNotices = guardedChanges;');
expect(noticeIdx).toBeGreaterThan(idx);
});
it('价格不受影响(仍走先改后通知),我方自建行也不在 guarded 里', () => {
const idx = service.indexOf('const guardedChanges = changes.filter');
// 窗口要覆盖"数量拦下 → 价格放行"整段(2026-10-14 起加工方式那道门已删)
const body = service.slice(idx, idx + 2600);
expect(body).toContain('priceQtyNotices = guardedChanges;');
// 仍然只对 guarded(= isMainSystemAllocatedLines 判定的主系统分配行)生效
expect(body).toContain('guarded.has(change.itemId)');
});
});
describe('小程序:明细接口带 main_order_code,数量格按行锁', () => {
it('订单管理端 / 采购员端明细查询都返回行级来源', () => {
expect(mobileAdmin).toMatch(/oi\.main_order_code/);
expect(mobilePurchaser).toMatch(/oi\.main_order_code/);
});
it('小程序按行判定 planQtyLocked,且点击数量格不进编辑弹窗', () => {
expect(mpJs).toContain('planQtyLocked: Boolean(String(row.main_order_code || \'\').trim())');
// 点击给一句说明(开发者 2026-10-10 定稿文案:「分发订单的数量无法修改」),然后不进编辑弹窗
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) \{/);
expect(mpJs).toContain("'分发订单的数量无法修改'");
expect(mpJs).toMatch(/wx\.showToast\(\{ title: '分发订单的数量无法修改', icon: 'none' \}\);/);
// 数量格带置灰样式(不加文案)
expect(mpWxml).toContain("{{item.planQtyLocked ? 'cell-locked' : ''}}");
});
it('我方正常录单不受影响:判据是**行上有 main_order_code**,不是整单标记', () => {
expect(mpJs).not.toMatch(/planQtyLocked: Boolean\([^)]*isMainSystemOrder/);
expect(mpJs).toMatch(/planQtyLocked: Boolean\(String\(row\.main_order_code/);
});
it('小程序:加工方式/加工方已解禁(仍与主系统行解耦,数量格照旧锁)', () => {
/**
* 三条门要一起开,否则出现"界面能改、保存 409"(2026-10-14 开发者报的正是这个):
* Web 详情(早前已开)+ 服务层(本次)+ 小程序(本次)。
*/
expect(mpJs).not.toContain('加工方式无法修改');
expect(mpWxml).not.toContain('disabled="{{item.planQtyLocked}}"');
expect(mpWxml).not.toContain('加工方式一起只读');
// 数量锁**不得**被顺手放开
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) \{/);
expect(mpWxml).toContain("class=\"g-td c-qty {{item.planQtyLocked ? 'cell-locked' : ''}}\"");
});
});
describe('主系统分配单:子系统不能新增商品行(2026-10-12)', () => {
const importService = readFileSync(
new URL('../src/services/mainSystemOrderImport.ts', import.meta.url),
'utf8'
);
it('服务层第二道门:主系统单新增行 ⇒ 400 main_system_order_no_manual_append', () => {
const idx = service.indexOf('子系统不能新增商品行');
expect(idx, '未找到主系统单禁止新增行的守卫').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 1800);
expect(body).toContain("code: 'main_system_order_no_manual_append'");
expect(body).toContain('public.main_system_order_imports');
// 边界(勿错伤):加菜放行 + 只对已存在的单生效 + 系统追加放行
expect(body).toContain('!params.allowMainSystemAppend');
expect(body).toContain('!newRowIsExtraDish');
expect(body).toContain('existingMap.size > 0');
});
it('主系统导入的系统追加放行(否则导入会被自己的门拦住)', () => {
expect(importService).toContain('allowMainSystemAppend: true');
});
});