fix: preserve Huizhou title ownership across formatting
This commit is contained in:
1 parent
90b7e50036
commit
80f9bde3cb
2 files changed
+24
-3
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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', '<br>'])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);
|
||||
|
||||
Reference in new issue
Block a user