From 80f9bde3cbfd0ca99287a3564818f265a5e2fa44 Mon Sep 17 00:00:00 2001 From: abaishu0730 Date: Wed, 21 Oct 2026 15:56:04 +0800 Subject: [PATCH] fix: preserve Huizhou title ownership across formatting --- src/modules/order-rules/title.cjs | 12 +++++++++--- tests/order-rules/huizhou-notification.test.cjs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/modules/order-rules/title.cjs b/src/modules/order-rules/title.cjs index 82bc305..2711ab1 100644 --- a/src/modules/order-rules/title.cjs +++ b/src/modules/order-rules/title.cjs @@ -21,10 +21,16 @@ function extractTitle(title){ if(label==='业务模式'){ const nextOrder=matches.findIndex((m,index)=>index>i&&m[1]==='订单号'); const between=nextOrder<0?[]:matches.slice(i+1,nextOrder).map(m=>m[1]); - // BPM starts the next paragraph with business mode + margin before its order number. - // Ordinary summary text remains byte-for-byte compatible with the existing extractor. + // Summary fields after a mode still belong to the current order, irrespective + // of line wrapping. Only a header with no intervening summary binds forward. const startsParagraph=/[\n|]\s*$/.test(text.slice(0,match.index)); - if(!current||nextOrder>=0&&(between.includes('毛利')||startsParagraph)){ + const hasOwnSummary=between.some(label=>Object.hasOwn(summaryKeys,label)); + const forward=nextOrder>=0&&!hasOwnSummary&&(between.includes('毛利')||startsParagraph); + if(current&&nextOrder>=0&&!hasOwnSummary&&!forward){ + // An unmarked boundary cannot establish which adjacent order owns the mode. + current.businessModeAmbiguous=true;pendingMode=value;pendingAmbiguous=true; + } + else if(!current||forward){ if(pendingMode&&pendingMode!==value)pendingAmbiguous=true; pendingMode=value; } diff --git a/tests/order-rules/huizhou-notification.test.cjs b/tests/order-rules/huizhou-notification.test.cjs index f8d8e33..9d0c781 100644 --- a/tests/order-rules/huizhou-notification.test.cjs +++ b/tests/order-rules/huizhou-notification.test.cjs @@ -50,6 +50,21 @@ test('conflicting business headers for the same segment remain visible Hui uncer const {selectHuizhou}=require('../../src/modules/order-rules/huizhou.cjs'); const selection=selectHuizhou({titleOrders:extractTitle('业务模式:普通业务模式:惠州订单号:H-200客户简称:惠州创维数字技术有限公司').orders});assert.equal(selection.orders.length,0);assert.equal(selection.issues.length,1); }); +for(const separator of ['', '\n', '
'])test('title mode ownership survives own-summary formatting '+JSON.stringify(separator),t=>{ + const title=['订单号:H-100','业务模式:惠州数字','客户简称:普通客户','订单号:O-200','客户简称:普通客户'].join(separator); + const f=fixture(t,{title}),{normal,hui}=pair(f);assert.deepEqual(hui.orderNos,['H-100']);assert.doesNotMatch(hui.subject+hui.text,/O-200/);assert.match(normal.text,/H-100/);assert.match(normal.text,/O-200/); +}); +for(const title of [ + '订单号:O-100客户简称:普通客户订单类别:参考订单订单类型:C业务模式:惠州数字毛利:绿标订单号:H-200客户简称:终端客户', + '订单号:O-100客户简称:普通客户\n业务模式:惠州数字\n毛利:绿标\n订单号:H-200客户简称:终端客户', + '业务模式:惠州数字订单号:H-200客户简称:终端客户订单号:O-100客户简称:普通客户' +])test('title prefix header keeps its following owner '+JSON.stringify(title),()=>{ + const {selectHuizhou}=require('../../src/modules/order-rules/huizhou.cjs'),selected=selectHuizhou({titleOrders:extractTitle(title).orders});assert.deepEqual(selected.orderNos,['H-200']);assert.deepEqual(selected.issues,[]); +}); +test('title mode at an unmarked boundary blocks Hui instead of silently choosing an adjacent order',t=>{ + const f=fixture(t,{title:'订单号:O-100客户简称:普通客户业务模式:惠州数字订单号:H-200客户简称:终端客户'}),batches=f.store.prepare(cutoff,'admin');assert.equal(batches.length,1);assert.equal(batches[0].notificationMode,'normal'); + const hui=orderDetail(f.context(),f.order.id,admin).notifications.huizhou;assert.equal(hui.status,'blocked');assert.deepEqual(hui.orderNos,[]);assert.ok(hui.issues.length); +}); for(const title of ['订单号:HA200客户简称:未知客户','订单号:H-200业务模式:普通客户简称:惠州创维数字技术有限公司'])test('uncertain evidence remains Hui-only and normal still freezes: '+title,t=>{ const f=fixture(t,{title}),batches=f.store.prepare(cutoff,'admin');assert.equal(batches.length,1);assert.equal(batches[0].notificationMode,'normal'); const detail=orderDetail(f.context(),f.order.id,admin);assert.equal(detail.notifications.huizhou.status,'blocked');assert.ok(detail.notifications.huizhou.issues.length);