Files
order-notification-automation/tests/bpm-detail-readonly.test.cjs
T
abaishu0730 94fc985553 feat: add guarded BPM category and template workflow
Implement server-owned read-only sample checks, category publication, explicit
order-version identity and durable PDF/archive/notification steps. Freeze
category-bound templates and recipients for isolated scheduled delivery, and
require human verification for unknown SMTP outcomes. Add order/batch views
and local HTTP/browser/PDF/archive regression coverage.

Fix Unicode Windows startup links found by full regression using IShellLinkW.
Automatic processing and sending stay disabled; no service deployment.

Validation: npm ci; npm test -- --test-concurrency=1 (242 pass, 1 optional
ZCode skip, 0 fail); 31 syntax checks; scoped independent code review.
Live BPM V13/SMB/163 acceptance remains pending.
2026-10-22 16:52:59 +08:00

27 lines
3.6 KiB
JavaScript

'use strict';
const test=require('node:test');const assert=require('node:assert/strict');
const {loadPlaywright,browserOptions}=require('../src/runtime.cjs');
const {readDetailDocument,allowDetailRequest,parseDetailUrl,captureDetail}=require('../src/bpm-order-detail.cjs');
test('BPM detail request policy blocks actions, uploads, redirects and other hosts',()=>{
const url='https://bpm.skyworthdigital.com/YZSoft/Forms/XForm/海外运营订单评审V13.aspx?tid=1&pid=2';
assert.equal(allowDetailRequest(url,'GET',url,true),true);
assert.equal(allowDetailRequest(url,'POST',url,true),false);
assert.equal(allowDetailRequest('https://bpm.skyworthdigital.com/ASHX/Approve.ashx?method=read','GET',url,false),false);
assert.equal(allowDetailRequest('https://evil.example/x.js','GET',url,false),false);
assert.equal(allowDetailRequest(url+'&action=approve','GET',url,true),false);
assert.throws(()=>parseDetailUrl(url+'&tid=3'));
});
test('capture waits for a visible binding even when the first bound field is hidden',async t=>{
const http=require('node:http'),server=http.createServer((req,res)=>{res.setHeader('Content-Type','text/html; charset=utf-8');res.end('<form><input type="hidden" xdatabind="old" value="999999"><span xdatabind="OFR_WY_Applicant.OrderNum">000123</span><table><tr><th>节点</th><th>状态</th></tr><tr><td>N</td><td>处理中</td></tr></table></form>');});await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));t.after(()=>new Promise(resolve=>server.close(resolve)));
const browserFactory=async()=>{const browser=await loadPlaywright().chromium.launch(browserOptions());return {close:()=>browser.close(),newContext:async options=>{const context=await browser.newContext(options),route=context.route.bind(context);context.route=async(pattern,handler)=>route(pattern,request=>handler({request:()=>request.request(),fetch:options=>request.fetch({...options,url:'http://127.0.0.1:'+server.address().port}),fulfill:options=>request.fulfill(options),abort:()=>request.abort()}));return context;}};};
const result=await captureDetail({storageState:{cookies:[],origins:[]},detailUrl:'https://bpm.skyworthdigital.com/YZSoft/Forms/XForm/PV1.aspx?tid=1&pid=2',processName:'P',nodeName:'N',browserFactory,timeout:1500});
assert.equal(result.detail.fields['OFR_WY_Applicant.OrderNum'],'000123');assert.equal(result.detail.tid,'1');assert.equal(result.detail.readOnly,true);assert.equal(result.detail.businessVersion,undefined);assert.match(result.evidenceHash,/^[a-f0-9]{64}$/);
});
test('read-only DOM extraction uses visible explicit xdatabind spans and never hidden originals',async t=>{
const browser=await loadPlaywright().chromium.launch(browserOptions());t.after(()=>browser.close());const page=await browser.newPage();
await page.setContent(`<form><input type="hidden" xdatabind="OFR_WY_Applicant.OrderNum" value="999999"><span xdatabind="OFR_WY_Applicant.OrderNum">000123</span><textarea xdatabind="OFR_WY_BInfo.CustomerName">A\nB</textarea><input type="password" xdatabind="secret" value="NEVER"><table data-process-steps><tr><th>节点</th><th>状态</th></tr><tr><td>订单专员(生效)</td><td>处理中</td></tr></table><button onclick="throw Error('write')">审批</button></form>`);
const data=await page.evaluate(readDetailDocument);
assert.equal(data.elements.find(x=>x.binding==='OFR_WY_Applicant.OrderNum').value,'000123');assert.equal(data.elements.some(x=>x.binding==='secret'),false);
assert.equal(data.processSteps[0].name,'订单专员(生效)');assert.equal(data.processSteps[0].status,'处理中');assert.doesNotMatch(data.snapshot.html,/NEVER|999999|onclick|<button/);
});