fix: expose observed historical processes in matching catalog
This commit is contained in:
1 parent
b17b975812
commit
c3e948d2e4
12 files changed
+147
-20
No files matched your search
@@ -1,5 +1,13 @@
|
||||
# 开发交接(2026-10-23)
|
||||
|
||||
## 2026-10-26 匹配页面流程目录接入修复
|
||||
|
||||
- 规则共涉及29个流程,旧scope-catalog只含其中14个;其余15个中14个已有真实历史采集样本,曾被整个拒绝目录接入。新增scope-process-catalog保留历史流程名与来源,directory新增processes,原scopes仍是精确流程/节点配对。既有目录配置不再阻止一次性迁移;停用采集时延后,恢复后执行。
|
||||
- 匹配页流程下拉及字段目录显示process-only历史流程;无节点则显示节点待采集。Excel已知名称保留原标点,导入不写采集目录。历史占位节点不进入选择项。
|
||||
- 当前只读取得19个历史实例ProcessStep记录(458条步骤),内部方法只保存节点名称、实例/版本/采集时间等来源证据,不保存人员意见,不创建通知事件。计划写入后规则涉及流程可确认28/29;剩余指定节点与实采名称差异继续保留提示,不自动替换Excel。
|
||||
- 真实历史原始证据与差异回执只在忽略output/business-flow-test/catalog-node-evidence-20261026.json及history-catalog-applied-20261026.json;五天测试规则、适配器、订单、批次、签名与邮件数据不因目录完善改变。历史ProcessStep不提供原通知任务ID/到达时间,不能据此自动补发。
|
||||
- 验证:126项业务回归通过;新增历史名称、精确历史节点、停用/重启/原标点和UI可选项测试先失败后通过。目录预演显示36个实际流程、401个已观测配对,规则涉及28/29流程;仍未观察到的17个Excel指定配对保留提示,包含实际名称差异和样本尚未走到节点的情况,不能据此自动修改规则。
|
||||
|
||||
## 2026-10-26 剩余阻塞与读取速度优化
|
||||
|
||||
- 发现屏障独立到discovery-barrier.cjs。停用来源的旧待交付/待处理线索只保留证据,不阻断无关的新批次;活动来源及未移除相关不确定任务仍严格检查。
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# 匹配页面历史流程目录补全
|
||||
|
||||
用户澄清“很多没有采集到的流程”指规则匹配页面流程候选,不是当前订单数量。
|
||||
|
||||
- 已保存的服务端历史样本证明流程名称,但旧目录只接纳当前待办/待阅配对,导致14个已采集流程被误标未知。增加独立流程名目录,保留来源证据;一次迁移现有可信样本,不读取Excel/规则生成采集名称。
|
||||
- 当前只读核验19个真实历史实例的ProcessStep步骤,补实际节点候选;不将历史实例变成当前通知事件,不生成taskId/到达时间,不自动修改规则、适配器或发送范围。
|
||||
- 流程选项显示全部已观测流程,节点仍仅使用实际配对;流程已知但未采到目标节点继续提示并禁止新发布。已知全角标点保留,Excel导入不反写目录。
|
||||
- 先失败测试后实现,验证旧目录升级、停用、重启、精确节点、权限和UI选择;备份更新本机测试副本,目录写入前后核对规则和业务数据哈希。
|
||||
- 剩余Excel与BPM名称差异保存明细,需业务确认后才修改,不自动建立别名。零售国内返工订单更改评审仍无当前账号可用样本。
|
||||
@@ -9,7 +9,7 @@ async function template(store,{importTemplate=false}={}){
|
||||
for(const {draft:r}of store.all('rules'))for(const scope of require('./scopes.cjs').scopesFor(r))sheet.addRow([r.id,r.name,scope.processName,scope.nodeName,r.archiveDirectory,r.subjectPrefix,r.bodyTemplateId||'',r.productLine||'',r.to.join('\n'),r.cc.join('\n'),dates[r.filenameDate]||'']);
|
||||
const help=book.addWorksheet('填写说明');help.getColumn(1).width=110;
|
||||
for(const line of ['每行填写一个流程和触发节点,同一分类可重复多行,其余业务配置必须一致。','类别编号使用现有分类编号;模板已带入当前规则,可删去不需修改的分类行。','流程和节点请参考BPM可选项工作表;这是BPM实际采集目录,不由Excel维护。','未知流程或节点会逐行警告,可保存草稿,但不能应用到测试或正式发布。','邮件模板ID填写已有普通邮件模板ID;留空沿用分类原有模板。','收件人、抄送人可用换行或分号分隔;归档目录填写完整共享路径。','文件名日期填写申请日期、接收日期或归档日期。','导入只修改分类草稿,不自动启用、归档或发送邮件;PDF不作邮件附件。','本文件最多200行数据;采集未覆盖不代表BPM一定不存在,请检查Excel或补充采集。'])help.addRow([line]);
|
||||
const choices=book.addWorksheet('BPM可选项');choices.columns=[{header:'流程名称',width:45},{header:'触发节点',width:45}];for(const row of require('./scope-catalog.cjs').directory(store).scopes)choices.addRow([row.processName,row.nodeName]);
|
||||
const choices=book.addWorksheet('BPM可选项');choices.columns=[{header:'流程名称',width:45},{header:'触发节点',width:45}];const directory=require('./scope-catalog.cjs').directory(store);for(const row of directory.scopes)choices.addRow([row.processName,row.nodeName]);for(const processName of directory.processes)if(!directory.scopes.some(s=>s.processName===processName))choices.addRow([processName,'']);
|
||||
for(const s of [sheet,choices]){s.views=[{state:'frozen',ySplit:1}];s.getRow(1).font={bold:true};s.eachRow(row=>row.alignment={vertical:'top',wrapText:true});}sheet.autoFilter='A1:K1';choices.autoFilter='A1:B1';
|
||||
return Buffer.from(await book.xlsx.writeBuffer());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ function previewImport(store,input,actor,{mail}={}){
|
||||
const headers=input.rows[0].map(v=>aliases[String(v).trim()]||String(v).trim());if(new Set(headers.filter(Boolean)).size!==headers.filter(Boolean).length)fail('Excel 列名重复,请检查表头。');
|
||||
for(const name of ['订单评审流程','电子流状态','邮件命名','收件人'])if(!headers.includes(name))fail('缺少 Excel 列:'+name);
|
||||
const originals=store.all('rules'),rows=[],seen=new Map();
|
||||
const knownScopes=require('./scope-catalog.cjs').directory(store).scopes,knownProcesses=new Set(knownScopes.map(s=>s.processName)),knownNodes=new Set(knownScopes.map(s=>s.nodeName)),canonical=value=>knownProcesses.has(value)||knownNodes.has(value)?value:value.normalize('NFKC');
|
||||
const catalog=require('./scope-catalog.cjs').directory(store),knownScopes=catalog.scopes,knownProcesses=new Set(catalog.processes),knownNodes=new Set(knownScopes.map(s=>s.nodeName)),canonical=value=>knownProcesses.has(value)||knownNodes.has(value)?value:value.normalize('NFKC');
|
||||
input.rows.slice(1).forEach((cells,index)=>{
|
||||
const get=name=>String(cells[headers.indexOf(name)]??'').trim();if(!cells.some(c=>String(c).trim()))return;
|
||||
const row={sourceRow:index+2,name:get('分类名称'),issues:[],warnings:[],changes:[]};rows.push(row);
|
||||
|
||||
@@ -4,35 +4,70 @@ const {fail}=require('./validation.cjs');
|
||||
const {scopesFor}=require('./scopes.cjs');
|
||||
const settings=store=>store.get('scope-catalog-settings','main')||{id:'main',version:1,enabled:true};
|
||||
const clean=value=>typeof value==='string'&&value.trim()&&value.length<=250&&!/[\x00-\x1f]/.test(value)?value.trim():'';
|
||||
function observe(store,rows){
|
||||
const hash=value=>crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
||||
function observeProcess(store,row,evidence){
|
||||
const processName=clean(row.processName);if(!processName)return;
|
||||
const id=hash(processName);
|
||||
if(!store.get('scope-process-catalog',id))store.put('scope-process-catalog',{id,processName,discoveredAt:store.now(),provenance:'server-provider',evidence:{source:row.source,capturedAt:store.now(),...evidence}});
|
||||
}
|
||||
function observe(store,rows,evidence={recordKind:'server-observation'}){
|
||||
if(!settings(store).enabled)return;
|
||||
for(const row of rows){
|
||||
if(!['todo','inform'].includes(row?.source)||row.demo||row.configurationOnly&&row.source!=='todo')continue;
|
||||
if(!['todo','inform','history'].includes(row?.source)||row.demo||row.configurationOnly&&!['todo','history'].includes(row.source))continue;
|
||||
observeProcess(store,row,evidence);
|
||||
if(row.source==='history')continue;
|
||||
const processName=clean(row.processName),nodeName=clean(row.nodeName||row.activityName);
|
||||
if(!processName||!nodeName||/历史查看|未提供办理节点/.test(nodeName))continue;
|
||||
const id=crypto.createHash('sha256').update(JSON.stringify([processName,nodeName])).digest('hex');
|
||||
if(!store.get('scope-catalog',id))store.put('scope-catalog',{id,processName,nodeName,discoveredAt:store.now()});
|
||||
}
|
||||
}
|
||||
// Internal only: callers must authenticate the BPM history instance and read ProcessStep.
|
||||
// Never expose this ingestion helper as a client-supplied catalog API.
|
||||
function observeHistoricalNodes(store,input){
|
||||
if(!settings(store).enabled)return directory(store);
|
||||
const invalid=()=>fail('历史节点证据无效,必须使用已核验的 ProcessStep 原始记录。',409);
|
||||
if(!input||input.evidenceSource!=='ProcessStep'||!clean(input.processName)||clean(input.processName)!==input.processName||typeof input.instanceId!=='string'||! /^[1-9]\d*$/.test(input.instanceId)||!clean(input.processVersion)||typeof input.capturedAt!=='string'||!/^\d{4}-\d{2}-\d{2}T.*(?:Z|[+-]\d{2}:\d{2})$/.test(input.capturedAt)||!Number.isFinite(Date.parse(input.capturedAt))||!Array.isArray(input.steps)||!input.steps.length||input.steps.length>1000)invalid();
|
||||
if(input.connectionId!==undefined&&(!clean(input.connectionId)||clean(input.connectionId)!==input.connectionId))invalid();
|
||||
const nodes=[];
|
||||
for(const step of input.steps){
|
||||
if(!step||!Number.isInteger(step.RowNum)||step.RowNum<1||!clean(step.NodeName)||clean(step.NodeName)!==step.NodeName||/历史查看|未提供办理节点/.test(step.NodeName))invalid();
|
||||
nodes.push(step.NodeName);
|
||||
}
|
||||
const evidence={source:'history-steps',evidenceSource:'ProcessStep',instanceId:input.instanceId,processVersion:input.processVersion,capturedAt:input.capturedAt,...(input.connectionId?{connectionId:input.connectionId}:{})};
|
||||
return store.transaction(()=>{
|
||||
observeProcess(store,{source:'history-steps',processName:input.processName},evidence);
|
||||
for(const nodeName of new Set(nodes)){
|
||||
const id=hash([input.processName,nodeName]);
|
||||
if(!store.get('scope-catalog',id))store.put('scope-catalog',{id,processName:input.processName,nodeName,discoveredAt:store.now(),evidence});
|
||||
}
|
||||
return directory(store);
|
||||
});
|
||||
}
|
||||
function initialize(store){
|
||||
if(store.get('scope-catalog-settings','main'))return;
|
||||
store.put('scope-catalog-settings',settings(store));
|
||||
const firstRun=!store.get('scope-catalog-settings','main');
|
||||
if(firstRun)store.put('scope-catalog-settings',settings(store));
|
||||
if(!settings(store).enabled||store.get('scope-catalog-migrations','process-evidence-v1'))return;
|
||||
// Only server-collected evidence; never seed from classification rules or imports.
|
||||
observe(store,store.all('capture-samples').filter(c=>c.provenance==='server-provider').map(c=>c.sample));
|
||||
for(const kind of ['execution-discovery-runs','field-sample-lists'])for(const record of store.all(kind))observe(store,(record.rows||[]).map(r=>r.row||r));
|
||||
for(const record of store.all('capture-samples'))if(record.provenance==='server-provider'&&record.sample)observe(store,[record.sample],{recordKind:'capture-samples',recordId:record.id,capturedAt:record.capturedAt||store.now()});
|
||||
for(const record of store.all('field-sample-lists'))if(record.connectionId&&record.owner&&/^[a-f0-9]{64}$/.test(record.sessionHash||'')&&Number.isFinite(Date.parse(record.createdAt)))observe(store,(record.rows||[]).map(r=>r.row||r),{recordKind:'field-sample-lists',recordId:record.id,capturedAt:record.createdAt});
|
||||
// Preserve the original initial pair backfill for execution runs; old catalogs already contain it.
|
||||
if(firstRun)for(const record of store.all('execution-discovery-runs'))observe(store,(record.rows||[]).map(r=>r.row||r),{recordKind:'execution-discovery-runs',recordId:record.id});
|
||||
store.put('scope-catalog-migrations',{id:'process-evidence-v1',completedAt:store.now()});
|
||||
}
|
||||
function directory(store){
|
||||
const {id,...config}=settings(store),scopes=store.all('scope-catalog').map(({processName,nodeName})=>({processName,nodeName})).sort((a,b)=>a.processName.localeCompare(b.processName,'zh-CN')||a.nodeName.localeCompare(b.nodeName,'zh-CN'));
|
||||
return {settings:config,scopes};
|
||||
const processes=[...new Set([...scopes.map(row=>row.processName),...store.all('scope-process-catalog').map(row=>row.processName)])].sort((a,b)=>a.localeCompare(b,'zh-CN'));
|
||||
return {settings:config,processes,scopes};
|
||||
}
|
||||
function configure(store,input,actor){
|
||||
if(actor?.role!=='admin'||!actor.username)fail('仅管理员可以维护字段映射。',403);
|
||||
return store.transaction(()=>{const old=settings(store);if(!input||Object.keys(input).some(k=>!['version','enabled'].includes(k))||typeof input.enabled!=='boolean')fail('字段映射开关无效。');if(input.version!==old.version)fail('字段映射设置已变化,请刷新重试。',409);
|
||||
store.put('scope-catalog-settings',{id:'main',version:old.version+1,enabled:input.enabled});store.audit(actor.username,'字段映射自动采集',input.enabled?'启用':'停用');return directory(store);});
|
||||
store.put('scope-catalog-settings',{id:'main',version:old.version+1,enabled:input.enabled});if(input.enabled)initialize(store);store.audit(actor.username,'字段映射自动采集',input.enabled?'启用':'停用');return directory(store);});
|
||||
}
|
||||
function warnings(store,rule){
|
||||
const scopes=directory(store).scopes;
|
||||
return scopesFor(rule).flatMap(row=>!scopes.some(s=>s.processName===row.processName)?['流程“'+row.processName+'”未在BPM字段映射中采集,请检查Excel或补充采集。']:!scopes.some(s=>s.processName===row.processName&&s.nodeName===row.nodeName)?['流程“'+row.processName+'”的节点“'+row.nodeName+'”未在BPM字段映射中采集,请检查Excel或补充采集。']:[]);
|
||||
const {scopes,processes}=directory(store);
|
||||
return scopesFor(rule).flatMap(row=>!processes.includes(row.processName)?['流程“'+row.processName+'”未在BPM字段映射中采集,请检查Excel或补充采集。']:!scopes.some(s=>s.processName===row.processName&&s.nodeName===row.nodeName)?['流程“'+row.processName+'”已采集,但节点“'+row.nodeName+'”未在BPM字段映射中采集,请检查Excel或补充采集。']:[]);
|
||||
}
|
||||
function assertKnown(store,rule){const issues=warnings(store,rule);if(issues.length)fail('字段映射与规则不一致:'+issues.join(';'),409);}
|
||||
module.exports={initialize,observe,directory,configure,warnings,assertKnown};
|
||||
module.exports={initialize,observe,observeHistoricalNodes,directory,configure,warnings,assertKnown};
|
||||
@@ -19,6 +19,13 @@ test('Excel scope import uses the same Unicode normalization as the authoritativ
|
||||
const overseas=store.get('rules','overseas-notice').draft,p=previewImport(store,sourceRows(overseas),'admin');commitImport(store,{id:p.id},'admin');
|
||||
assert.deepEqual(store.get('rules',overseas.id).draft.nodeNames,['订单专员(订单通知书)']);
|
||||
});
|
||||
|
||||
test('historically observed process names keep their punctuation while missing nodes still warn',()=>{
|
||||
const store=fixture(),catalog=require('../../src/modules/order-rules/scope-catalog.cjs'),name='历史流程(国内)';
|
||||
catalog.observe(store,[{source:'history',configurationOnly:true,processName:name,nodeName:'历史查看(未提供办理节点)'}]);
|
||||
const old=store.get('rules','bs-change').draft,input=sourceRows(old);input.rows[1][2]=name;
|
||||
const plan=previewImport(store,input,'admin');assert.equal(plan.canCommit,true);assert.equal(plan.rows[0].preview.scopes[0].processName,name);assert.ok(plan.rows[0].warnings.some(w=>/节点/.test(w)));assert.deepEqual(catalog.directory(store).scopes,[]);
|
||||
});
|
||||
test('legacy Excel attachment descriptions and explicit yes cannot enable PDF email attachments',()=>{
|
||||
for(const explicit of [false,true]){
|
||||
const store=fixture(),old=store.get('rules','bs-change').draft,input=sourceRows(old,'附件:订单通知书PDF');
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict');
|
||||
const {orderDrivenUI}=require('../fixtures/order-driven-ui.cjs');
|
||||
test('field mapping lists and searches known historical processes with nodes pending collection',{timeout:60000},async t=>{
|
||||
const {page,runtime}=await orderDrivenUI(t),s=runtime.orderRules,before=s.all('rules');
|
||||
require('../../src/modules/order-rules/scope-catalog.cjs').observe(s,[{source:'history',processName:'历史可信流程',nodeName:'历史查看'}]);
|
||||
await page.getByRole('button',{name:'刷新目录',exact:true}).click();await page.getByRole('cell',{name:'历史可信流程',exact:true}).waitFor();
|
||||
assert.match(await page.locator('#fm-count').textContent(),/2 个流程 · 1 个流程节点配对/);assert.match(await page.locator('#fm-rows').textContent(),/节点待采集/);assert.doesNotMatch(await page.locator('#fm-rows').textContent(),/历史查看/);
|
||||
await page.locator('#fm-search').fill('历史可信');assert.equal(await page.locator('#fm-rows tr').count(),1);assert.equal(await page.getByRole('cell',{name:'历史可信流程',exact:true}).count(),1);
|
||||
await page.locator('#fm-search').fill('订单专员');assert.equal(await page.getByRole('cell',{name:'历史可信流程',exact:true}).count(),0);assert.equal(await page.getByRole('cell',{name:'备损订单更改评审',exact:true}).count(),1);assert.deepEqual(s.all('rules'),before);
|
||||
});
|
||||
test('field mapping page shows only persisted processes/nodes and toggles collection without editing rules',{timeout:60000},async t=>{
|
||||
const {page,runtime}=await orderDrivenUI(t);const before=runtime.orderRules.all('rules');
|
||||
await page.getByRole('switch',{name:'自动采集流程和节点',exact:true}).waitFor();
|
||||
|
||||
@@ -2,6 +2,50 @@
|
||||
const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
const {RuleStore}=require('../../src/modules/order-rules/store.cjs');
|
||||
const catalog=()=>require('../../src/modules/order-rules/scope-catalog.cjs');
|
||||
test('authenticated historical steps retain exact node names and only minimal evidence across restart',t=>{
|
||||
const f=fixture(t),s=f.store,c=catalog(),beforeRules=s.all('rules'),beforeAdapters=s.all('field-adapters');
|
||||
assert.equal(typeof c.observeHistoricalNodes,'function');
|
||||
const input={processName:'历史流程(国内)',instanceId:'2456882',processVersion:'1.6',evidenceSource:'ProcessStep',capturedAt:'2026-10-26T08:42:50.817Z',connectionId:'bpm',steps:[{RowNum:1,NodeName:'订单通知书',HandlerAccount:'private-handler',Comments:'private-comment',FinishAt:null},{RowNum:2,NodeName:'审核(国内)/复核+归档',SelAcount:'private-user'}]};
|
||||
c.observeHistoricalNodes(s,input);c.observeHistoricalNodes(s,input);
|
||||
assert.equal(c.directory(s).scopes.length,2);assert(c.directory(s).scopes.some(r=>r.nodeName==='订单通知书'));assert(!c.directory(s).scopes.some(r=>r.nodeName==='订单专员(订单通知书)'));
|
||||
assert.equal(c.warnings(s,{scopes:[{processName:input.processName,nodeName:'订单通知书'}]}).length,0);
|
||||
assert.equal(c.warnings(s,{scopes:[{processName:input.processName,nodeName:'订单专员(订单通知书)'}]}).length,1);
|
||||
const records=s.all('scope-catalog');assert(records.every(r=>r.evidence.source==='history-steps'&&r.evidence.instanceId==='2456882'&&r.evidence.processVersion==='1.6'));
|
||||
assert(!JSON.stringify([...records,...s.all('scope-process-catalog')]).includes('private-'));assert.deepEqual(s.all('rules'),beforeRules);assert.deepEqual(s.all('field-adapters'),beforeAdapters);const before=c.directory(s);assert.deepEqual(c.directory(f.reopen()).scopes,before.scopes);
|
||||
});
|
||||
test('historical node collection rejects malformed evidence atomically and obeys disabled collection',t=>{
|
||||
const s=fixture(t).store,c=catalog();assert.equal(typeof c.observeHistoricalNodes,'function');
|
||||
const valid={processName:'历史流程',instanceId:'2456882',processVersion:'1.6',evidenceSource:'ProcessStep',capturedAt:'2026-10-26T08:42:50.817Z',steps:[{RowNum:1,NodeName:'订单通知书'}]};
|
||||
for(const patch of [{instanceId:'fake-id'},{processVersion:''},{capturedAt:'yesterday'},{evidenceSource:'Excel'},{steps:[]},{steps:Array.from({length:1001},(_,i)=>({RowNum:i+1,NodeName:'节点'}))},{steps:[...valid.steps,{RowNum:0,NodeName:'坏节点'}]},{steps:[...valid.steps,{RowNum:2,NodeName:'历史查看(未提供办理节点)'}]}]){
|
||||
assert.throws(()=>c.observeHistoricalNodes(s,{...valid,...patch}),/历史节点证据/);assert.deepEqual(c.directory(s).scopes,[]);assert.deepEqual(c.directory(s).processes,[]);
|
||||
}
|
||||
c.configure(s,{version:1,enabled:false},{role:'admin',username:'admin'});const before=c.directory(s);c.observeHistoricalNodes(s,valid);assert.deepEqual(c.directory(s),before);
|
||||
});
|
||||
test('historical server observations expose process names without inventing node evidence',t=>{
|
||||
const s=fixture(t).store,c=catalog();
|
||||
c.observe(s,[{source:'history',configurationOnly:true,processName:'历史流程(国内)',nodeName:'历史查看(未提供办理节点)'},{source:'history',demo:true,processName:'演示流程',nodeName:'节点甲'}]);
|
||||
assert.deepEqual(c.directory(s).processes,['历史流程(国内)']);assert.deepEqual(c.directory(s).scopes,[]);
|
||||
assert.match(c.warnings(s,{scopes:[{processName:'历史流程(国内)',nodeName:'真实待采节点'}]})[0],/节点.*真实待采节点/);
|
||||
assert.throws(()=>c.assertKnown(s,{scopes:[{processName:'历史流程(国内)',nodeName:'真实待采节点'}]}),e=>e.status===409);
|
||||
});
|
||||
test('existing catalog settings migrate trusted historical samples once and never seed from rules',t=>{
|
||||
const f=fixture(t),s=f.store,c=catalog();
|
||||
s.db.prepare("DELETE FROM records WHERE kind = 'scope-catalog-migrations'").run();
|
||||
s.put('capture-samples',{id:'actual',provenance:'server-provider',capturedAt:s.now(),sample:{source:'history',configurationOnly:true,processName:'历史流程',nodeName:'历史查看(未提供办理节点)'}});
|
||||
s.put('capture-samples',{id:'untrusted',provenance:'import',sample:{source:'history',processName:'导入流程',nodeName:'节点甲'}});
|
||||
s.put('field-sample-lists',{id:'unbound',rows:[{row:{source:'history',processName:'无来源流程'}}]});
|
||||
s.put('field-sample-lists',{id:'bound',connectionId:'bpm',owner:'admin',sessionHash:'a'.repeat(64),createdAt:s.now(),scope:'history',rows:[{id:'one',row:{source:'history',processName:'列表流程',nodeName:'历史查看(未提供办理节点)'}}]});
|
||||
c.initialize(s);assert.deepEqual(c.directory(s).processes,['历史流程','列表流程']);assert.deepEqual(c.directory(s).scopes,[]);
|
||||
const records=s.all('scope-process-catalog');assert(records.every(r=>r.evidence.recordId&&r.evidence.recordKind));
|
||||
c.initialize(s);assert.deepEqual(s.all('scope-process-catalog'),records);assert.deepEqual(c.directory(f.reopen()).processes,['历史流程','列表流程']);
|
||||
});
|
||||
test('disabled collection defers history migration and all observations until enabled',t=>{
|
||||
const s=fixture(t).store,c=catalog();s.db.prepare("DELETE FROM records WHERE kind = 'scope-catalog-migrations'").run();
|
||||
c.configure(s,{version:1,enabled:false},{role:'admin',username:'admin'});
|
||||
s.put('capture-samples',{id:'actual',provenance:'server-provider',sample:{source:'history',processName:'历史流程'}});
|
||||
c.initialize(s);c.observe(s,[{source:'history',processName:'临时流程'}]);assert.deepEqual(c.directory(s).processes,[]);
|
||||
c.configure(s,{version:2,enabled:true},{role:'admin',username:'admin'});c.initialize(s);assert.deepEqual(c.directory(s).processes,['历史流程']);
|
||||
});
|
||||
function fixture(t){const dir=fs.mkdtempSync(path.join(os.tmpdir(),'scope-catalog-'));let store=new RuleStore(dir);t.after(()=>{store.close();assert.equal(path.dirname(fs.realpathSync(dir)).toLowerCase(),fs.realpathSync(os.tmpdir()).toLowerCase());fs.rmSync(dir,{recursive:true,force:true});});return {get store(){return store;},reopen(){store.close();store=new RuleStore(dir);return store;}};}
|
||||
test('BPM directory persists only observed process/node pairs and pauses discovery without deleting choices',t=>{
|
||||
const f=fixture(t),c=catalog(),s=f.store;assert.deepEqual(c.directory(s).scopes,[]);
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict');
|
||||
const {orderDrivenUI}=require('../fixtures/order-driven-ui.cjs');
|
||||
test('historical process evidence is searchable without inventing nodes or changing published rules',{timeout:60000},async t=>{
|
||||
const {page,runtime}=await orderDrivenUI(t,'#order-rules'),s=runtime.orderRules,catalog=require('../../src/modules/order-rules/scope-catalog.cjs');
|
||||
catalog.observe(s,[{source:'history',processName:'历史可信流程',nodeName:'历史查看'}]);
|
||||
const record=s.get('rules','bs-change');record.draft.scopes=[{processName:'历史可信流程',nodeName:'Excel待核节点'},{processName:'Excel独有流程',nodeName:'Excel独有节点'}];record.draft.processNames=['历史可信流程','Excel独有流程'];record.draft.nodeNames=['Excel待核节点','Excel独有节点'];s.put('rules',record);const before=s.all('rules');
|
||||
await page.getByRole('button',{name:'刷新规则与字段',exact:true}).click();await page.locator('[data-rule-id="bs-change"]').click();
|
||||
assert.doesNotMatch(await page.locator('#scope-process-0').textContent(),/未在BPM采集/);assert.match(await page.locator('#scope-process-1').textContent(),/Excel独有流程(未在BPM采集)/);
|
||||
await page.getByRole('button',{name:'添加流程节点',exact:true}).click();const process=page.locator('#scope-process-2-ts-control');await process.fill('历史可信');await page.locator('#scope-process-2-ts-dropdown [data-selectable]').getByText('历史可信流程',{exact:true}).click();
|
||||
assert.equal(await page.locator('#scope-node-2').inputValue(),'');assert.equal(await page.locator('#scope-node-2 option[value]:not([value=""])').count(),0);assert.equal(await page.locator('#scope-node-2-ts-control').getAttribute('placeholder'),'节点待采集');
|
||||
await page.locator('#scope-node-2-ts-control').fill('Excel待核节点');assert.equal(await page.locator('#scope-node-2-ts-dropdown [data-selectable]').count(),0);assert.deepEqual(s.all('rules'),before);
|
||||
});
|
||||
test('scope comboboxes search actual BPM choices, cascade nodes and preserve the internal Excel identity',{timeout:60000},async t=>{
|
||||
const {page,runtime}=await orderDrivenUI(t,'#order-rules'),s=runtime.orderRules,catalog=require('../../src/modules/order-rules/scope-catalog.cjs');
|
||||
catalog.observe(s,[{source:'todo',processName:'海外运营订单评审',nodeName:'海外通知节点'},{source:'todo',processName:'海外IPC订单评审',nodeName:'IPC通知节点'}]);
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
const live=()=>!disposed&&isActive(),key=()=>window.PageLifecycle.requestKey();
|
||||
function lock(value){busy=value;host.setAttribute('aria-busy',String(value));host.querySelectorAll('button,input,select').forEach(e=>e.disabled=value||e.dataset.admin==='true'&&!admin);const discover=host.querySelector('#fm-discover');if(discover)discover.disabled=value||!data?.settings.enabled||!connections.length;}
|
||||
async function load(){const request=++revision;const fresh=await api('/order-rules/fields?view=scopes');if(!live()||request!==revision)return;data=fresh;draw();}
|
||||
function rows(){const scopes=data.scopes.filter(s=>(s.processName+' '+s.nodeName).toLocaleLowerCase().includes(query.toLocaleLowerCase())),groups=new Map();for(const s of scopes){if(!groups.has(s.processName))groups.set(s.processName,[]);groups.get(s.processName).push(s.nodeName);}host.querySelector('#fm-count').textContent=new Set(data.scopes.map(s=>s.processName)).size+' 个流程 · '+data.scopes.length+' 个流程节点配对';host.querySelector('#fm-rows').innerHTML=[...groups].map(([process,nodes])=>'<tr><td class="text-break">'+esc(process)+'</td><td class="text-break">'+nodes.map(n=>'<div>'+esc(n)+'</div>').join('')+'</td></tr>').join('')||'<tr><td colspan="2" class="text-secondary">'+(query?'没有匹配的流程或节点。':'尚未采集到流程和节点,请选择BPM连接更新。')+'</td></tr>';}
|
||||
function rows(){
|
||||
const processes=[...new Set([...(data.processes||[]),...data.scopes.map(s=>s.processName)])],groups=new Map(processes.map(process=>[process,[]])),search=query.toLocaleLowerCase();
|
||||
for(const scope of data.scopes)groups.get(scope.processName).push(scope.nodeName);
|
||||
const visible=[...groups].flatMap(([process,nodes])=>{if(process.toLocaleLowerCase().includes(search))return [[process,nodes]];const matches=nodes.filter(node=>node.toLocaleLowerCase().includes(search));return matches.length?[[process,matches]]:[];});
|
||||
host.querySelector('#fm-count').textContent=processes.length+' 个流程 · '+data.scopes.length+' 个流程节点配对';host.querySelector('#fm-rows').innerHTML=visible.map(([process,nodes])=>'<tr><td class="text-break">'+esc(process)+'</td><td class="text-break">'+(nodes.length?nodes.map(n=>'<div>'+esc(n)+'</div>').join(''):'<span class="text-secondary">节点待采集</span>')+'</td></tr>').join('')||'<tr><td colspan="2" class="text-secondary">'+(query?'没有匹配的流程或节点。':'尚未采集到流程和节点,请选择BPM连接更新。')+'</td></tr>';
|
||||
}
|
||||
async function act(work){if(busy||!live())return;lock(true);try{await work();}catch(e){if(live())feedback(e.message,'danger');}finally{if(live()){const toggle=host.querySelector('#fm-enabled');if(toggle)toggle.checked=data.settings.enabled;lock(false);}}}
|
||||
function draw(){
|
||||
const selected=host.querySelector('#fm-connection')?.value;
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
const scopesFor=rule=>Array.isArray(rule.scopes)?rule.scopes:(rule.processNames||[]).flatMap(processName=>(rule.nodeNames||[]).map(nodeName=>({processName,nodeName})));
|
||||
const read=host=>[...host.querySelectorAll('[data-scope-row]')].map(row=>({processName:row.querySelector('[data-scope-process]').value,nodeName:row.querySelector('[data-scope-node]').value}));
|
||||
function render(rule,{esc,admin}){return `<div id="rule-scopes" data-scopes="${esc(JSON.stringify(scopesFor(rule)))}"><div id="rule-scope-rows"></div>${admin?'<button type="button" class="btn btn-sm mt-2" id="rule-scope-add" aria-label="添加流程节点">+ 添加流程节点</button>':''}<p class="form-hint mt-2 mb-0">输入关键词搜索并选择流程、节点。任一行完整匹配即可归入本类别。</p></div>`;}
|
||||
function bind(host,{catalog,esc,admin,onChange}){
|
||||
function bind(host,{catalog,processes=catalog.map(r=>r.processName),esc,admin,onChange}){
|
||||
let rows=JSON.parse(host.dataset.scopes),controls=[];const mount=host.querySelector('#rule-scope-rows');
|
||||
const destroy=()=>{for(const control of controls)control.destroy();controls=[];};
|
||||
const nodePlaceholder=processName=>processName&&!catalog.some(r=>r.processName===processName)?'节点待采集':'输入关键词搜索节点';
|
||||
function draw(){
|
||||
destroy();
|
||||
const options=(values,current)=>['',...new Set([...values,current].filter(Boolean))].map(v=>`<option value="${esc(v)}" ${v===current?'selected':''}>${esc(v||'请选择')}${v&&!values.includes(v)?'(未在BPM采集)':''}</option>`).join('');
|
||||
mount.innerHTML=rows.map((row,i)=>`<div class="rule-scope-row" data-scope-row><div><label class="form-label" for="scope-process-${i}">第${i+1}行适用流程</label><select class="form-select" id="scope-process-${i}" data-scope-process ${admin?'required':'disabled'}>${options(catalog.map(r=>r.processName),row.processName)}</select></div><div><label class="form-label" for="scope-node-${i}">第${i+1}行触发节点</label><div class="input-group rule-scope-node-control"><select class="form-select" id="scope-node-${i}" data-scope-node ${admin?'required':'disabled'}>${options(catalog.filter(r=>r.processName===row.processName).map(r=>r.nodeName),row.nodeName)}</select>${admin?`<button class="btn btn-icon rule-scope-remove" type="button" data-scope-remove="${i}" aria-label="删除第${i+1}行">×</button>`:''}</div></div></div>`).join('')||'<p class="text-secondary small">尚未选择适用流程,添加一行后选择对应节点。</p>';
|
||||
mount.innerHTML=rows.map((row,i)=>`<div class="rule-scope-row" data-scope-row><div><label class="form-label" for="scope-process-${i}">第${i+1}行适用流程</label><select class="form-select" id="scope-process-${i}" data-scope-process ${admin?'required':'disabled'}>${options(processes,row.processName)}</select></div><div><label class="form-label" for="scope-node-${i}">第${i+1}行触发节点</label><div class="input-group rule-scope-node-control"><select class="form-select" id="scope-node-${i}" data-scope-node ${admin?'required':'disabled'}>${options(catalog.filter(r=>r.processName===row.processName).map(r=>r.nodeName),row.nodeName)}</select>${admin?`<button class="btn btn-icon rule-scope-remove" type="button" data-scope-remove="${i}" aria-label="删除第${i+1}行">×</button>`:''}</div></div></div>`).join('')||'<p class="text-secondary small">尚未选择适用流程,添加一行后选择对应节点。</p>';
|
||||
mount.querySelectorAll('[data-scope-remove]').forEach(button=>button.onclick=()=>{rows.splice(Number(button.dataset.scopeRemove),1);draw();onChange();});
|
||||
mount.querySelectorAll('[data-scope-process]').forEach((select,i)=>select.onchange=()=>{rows[i].processName=select.value;if(!catalog.some(r=>r.processName===select.value&&r.nodeName===rows[i].nodeName))rows[i].nodeName='';const node=select.closest('[data-scope-row]').querySelector('[data-scope-node]'),values=[...new Set(catalog.filter(r=>r.processName===select.value).map(r=>r.nodeName))];if(node.tomselect){node.tomselect.clear(true);node.tomselect.clearOptions();node.tomselect.addOptions(values.map(value=>({value,text:value})));node.tomselect.setValue(rows[i].nodeName,true);}else node.innerHTML=options(values,rows[i].nodeName);onChange();});
|
||||
mount.querySelectorAll('[data-scope-process]').forEach((select,i)=>select.onchange=()=>{rows[i].processName=select.value;if(!catalog.some(r=>r.processName===select.value&&r.nodeName===rows[i].nodeName))rows[i].nodeName='';const node=select.closest('[data-scope-row]').querySelector('[data-scope-node]'),values=[...new Set(catalog.filter(r=>r.processName===select.value).map(r=>r.nodeName))];if(node.tomselect){node.tomselect.clear(true);node.tomselect.clearOptions();node.tomselect.addOptions(values.map(value=>({value,text:value})));node.tomselect.setValue(rows[i].nodeName,true);node.tomselect.settings.placeholder=nodePlaceholder(select.value);node.tomselect.inputState();}else node.innerHTML=options(values,rows[i].nodeName);onChange();});
|
||||
mount.querySelectorAll('[data-scope-node]').forEach((select,i)=>select.onchange=()=>{rows[i].nodeName=select.value;onChange();});
|
||||
if(window.TomSelect)mount.querySelectorAll('[data-scope-process],[data-scope-node]').forEach(select=>controls.push(new window.TomSelect(select,{create:false,maxItems:1,maxOptions:1000,searchField:['text'],closeAfterSelect:true,selectOnTab:true,placeholder:select.hasAttribute('data-scope-process')?'输入关键词搜索流程':'输入关键词搜索节点',render:{no_results:()=>'<div class="no-results">没有匹配项</div>'}})));
|
||||
if(window.TomSelect)mount.querySelectorAll('[data-scope-process],[data-scope-node]').forEach(select=>controls.push(new window.TomSelect(select,{create:false,maxItems:1,maxOptions:1000,searchField:['text'],closeAfterSelect:true,selectOnTab:true,placeholder:select.hasAttribute('data-scope-process')?'输入关键词搜索流程':nodePlaceholder(select.closest('[data-scope-row]').querySelector('[data-scope-process]').value),render:{no_results:()=>'<div class="no-results">没有匹配项</div>'}})));
|
||||
const add=host.querySelector('#rule-scope-add');if(add)add.disabled=rows.length>=100;
|
||||
}
|
||||
const add=host.querySelector('#rule-scope-add');if(add)add.onclick=()=>{if(rows.length>=100)return;rows.push({processName:'',nodeName:''});draw();onChange();};draw();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
const optional=(path,kind)=>api(path).catch(error=>({error:{kind,message:error.message}}));
|
||||
const [snapshot,catalog,mail,bindings,storage,connections,scopes]=await Promise.all([api('/order-rules?view=summary'),optional('/order-rules/fields?view=directory','fields'),optional('/mail','mail'),optional('/mail/templates/categories','mail'),optional('/storage','storage'),admin?optional('/workspace','connections'):Promise.resolve({connections:[]}),optional('/order-rules/fields?view=scopes','scopes')]);
|
||||
if(!isActive()||request!==revision)return false;
|
||||
data={scopeCatalog:scopes.scopes||[],scopeError:scopes.error?.message,connections:connections.connections||[],rules:snapshot.rules||[],restrictedTest:snapshot.restrictedTest||null,adapters:snapshot.adapters||[],samples:catalog.samples||[],fieldProcesses:catalog.processes||[],catalogError:catalog.error?.message,resources:{templates:mail.templates||[],bindings:bindings.bindings||[],servers:storage.servers||[],errors:[mail.error,bindings.error,storage.error].filter(Boolean)}};dirty=false;draw();return true;
|
||||
data={scopeProcesses:scopes.processes,scopeCatalog:scopes.scopes||[],scopeError:scopes.error?.message,connections:connections.connections||[],rules:snapshot.rules||[],restrictedTest:snapshot.restrictedTest||null,adapters:snapshot.adapters||[],samples:catalog.samples||[],fieldProcesses:catalog.processes||[],catalogError:catalog.error?.message,resources:{templates:mail.templates||[],bindings:bindings.bindings||[],servers:storage.servers||[],errors:[mail.error,bindings.error,storage.error].filter(Boolean)}};dirty=false;draw();return true;
|
||||
}
|
||||
function draw(){
|
||||
unregister?.();resourceController?.dispose();scopeController?.dispose();++trialRevision;
|
||||
@@ -56,7 +56,7 @@
|
||||
}
|
||||
const catalog=data.scopeCatalog;
|
||||
if(data.scopeError)panel.querySelector('#rule-scopes').insertAdjacentHTML('afterbegin','<div class="alert alert-warning">字段映射目录读取失败:'+esc(data.scopeError)+'。请刷新重试;未加载时不能新增匹配项。</div>');
|
||||
scopeController=window.OrderRuleScopes.bind(panel.querySelector('#rule-scopes'),{catalog,esc,admin,onChange:changed});
|
||||
scopeController=window.OrderRuleScopes.bind(panel.querySelector('#rule-scopes'),{catalog,processes:data.scopeProcesses,esc,admin,onChange:changed});
|
||||
resourceController=window.OrderRuleResources.bind(form,data.resources,{api,esc,owned,changed,admin});baseline=JSON.stringify(read());coverage();
|
||||
const source=panel.querySelector('#order-rule-sample-source');
|
||||
function refreshSources(){const next=sourcesFor(read());if(JSON.stringify(next.map(a=>a.id))===JSON.stringify(sources.map(a=>a.id)))return;const selected=source.value;sources=next;panel.querySelector('#rule-recognition-empty').hidden=!!sources.length;source.innerHTML='<option value="">请选择真实订单</option>'+sources.map(a=>'<option value="'+esc(a.id)+'">'+esc(a.label)+'</option>').join('');source.value=sources.some(a=>a.id===selected)?selected:'';const check=panel.querySelector('#order-rule-preview');if(check)check.disabled=!sources.length;choose();}
|
||||
|
||||
Reference in new issue
Block a user