Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 3s
81 lines
5.3 KiB
JavaScript
81 lines
5.3 KiB
JavaScript
/** Render the registered native incident panel and exercise its cancel action offline. */
|
|
import assert from 'node:assert/strict';
|
|
import {readFile} from 'node:fs/promises';
|
|
import vm from 'node:vm';
|
|
|
|
let plugin,TaskPanel,data,stateIndex,tab='overview';
|
|
const requests=[];
|
|
const React={
|
|
createElement:(type,props,...children)=>({type,props:props||{},children}),
|
|
useState:()=>[[data,'',tab,false,null][stateIndex++],()=>{}],
|
|
useEffect:()=>{}
|
|
};
|
|
const sandbox={window:{__ModuleLoader__:{load:value=>{plugin=value;}}},
|
|
fetch:async(url,options)=>{
|
|
if(url==='/dx/context')return {ok:true,json:async()=>({...data,revision:'fresh-revision'})};
|
|
requests.push({url,body:JSON.parse(options.body)});
|
|
return {ok:true,status:200};
|
|
}};
|
|
vm.runInNewContext(await readFile(new URL('../integration/dsh/task-plugin/client.js',import.meta.url),'utf8'),sandbox);
|
|
const exported=plugin.factory(name=>name==='react'?React:{});
|
|
exported.apply({effect:()=>{},slots:{inject:(_name,callback)=>callback(),register:(slot,component)=>{
|
|
if(slot.name==='sidebar.right.pane.tab')TaskPanel=component;
|
|
}},sidebarRightTabs:{register:()=>{}},sidebarRight:{mounted:{}}});
|
|
|
|
function expand(node){
|
|
if(Array.isArray(node))return node.flatMap(part=>expand(part));
|
|
if(node===null||node===undefined||typeof node==='boolean')return [];
|
|
if(typeof node!=='object')return [String(node)];
|
|
if(typeof node.type==='function')return expand(node.type({...node.props,children:node.children}));
|
|
return [{...node,children:node.children.flatMap(part=>expand(part))}];
|
|
}
|
|
const nodes=tree=>tree.flatMap(node=>typeof node==='object'?[node,...nodes(node.children)]:[]);
|
|
const text=tree=>tree.map(node=>typeof node==='object'?text(node.children):node).join('');
|
|
function render(automation){
|
|
data={task_id:'selected-task',revision:'current-revision',progress:{},rules_count:0,
|
|
automation:{incident_id:'incident',task_id:'',...automation}};
|
|
stateIndex=0;
|
|
return expand(TaskPanel());
|
|
}
|
|
const element=(tree,id)=>nodes(tree).find(node=>node.props['data-testid']===id);
|
|
|
|
let tree=render({status:'resolved',cleanup_attempts:1,verification:{verification_status:'complete',cleanup_performed:true,resources_released:true,remaining_resources:[]}});
|
|
assert.match(text([element(tree,'dx-auto-cleanup-attempts')]),/1/);
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/资源释放已独立核验通过/);
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/不代表 CAD 任务成功/);
|
|
tree=render({status:'pending_issue',cleanup_attempts:1,verification:{resources_released:false,remaining_resources:[{}]}});
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/剩余 1 项资源/);
|
|
tree=render({status:'pending_issue',cleanup_attempts:0,verification:{resources_released:false,remaining_resources:null}});
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/剩余资源数量未知/);
|
|
tree=render({status:'pending_issue',cleanup_attempts:1,verification:{resources_released:false,remaining_resources:[{}, {__truncated__:true}]}});
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/至少 1 项资源/);
|
|
tree=render({status:'observed_cleared',cleanup_attempts:0,verification:{verification_status:'observed_cleared',cleanup_performed:false,resources_released:true,remaining_resources:[]}});
|
|
assert.equal(text([element(tree,'dx-auto-status')]),'阻塞已自行解除,未执行清理');
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/未执行 AI 清理/);
|
|
assert.ok(!text([element(tree,'dx-auto-verification')]).includes('核验通过'));
|
|
assert.ok(!text(tree).includes('正在保留现场'),'a cleared incident must not still claim diagnosis is running');
|
|
assert.equal(element(tree,'dx-auto-cancel'),undefined);
|
|
tree=render({status:'cancelled',cleanup_attempts:0,can_cancel:false});
|
|
assert.equal(text([element(tree,'dx-auto-status')]),'诊断已取消,证据已保留');
|
|
assert.ok(!text(tree).includes('正在保留现场'),'a cancelled incident must not still claim diagnosis is running');
|
|
assert.equal(element(tree,'dx-auto-cancel'),undefined);
|
|
tree=render({status:'cancelled',cleanup_attempts:1,verification:{verification_status:'complete',cleanup_performed:true,resources_released:true,remaining_resources:[]}});
|
|
assert.match(text([element(tree,'dx-auto-verification')]),/取消前已执行清理/);
|
|
tree=render({status:'analyzing',task_id:'other-incident-task',can_cancel:true});
|
|
const cancel=element(tree,'dx-auto-cancel');
|
|
assert.ok(cancel,'an active diagnosis can be cancelled after selecting another task');
|
|
assert.equal(text([cancel]),'取消 AI 诊断');
|
|
await cancel.props.onClick();
|
|
assert.equal(requests.length,1);
|
|
assert.deepEqual(requests[0],{url:'/dx/action',body:{action:'cancel_diagnosis',task_id:'selected-task',revision:'fresh-revision'}});
|
|
tab='impact';
|
|
data={task_id:'selected-task',operations:{impact:{coverage:'exact',component_count:1,rows:[{
|
|
task_id:'selected-task',uid:'target',enabled:true,component_count:1,value_mode:'part_number',
|
|
value_policy:'part_number',old_part_number:'OLD',new_part_number:'NEW',old_value:'ORIGINAL',proposed_value:'NEW'
|
|
}]}}};
|
|
stateIndex=0;
|
|
tree=expand(TaskPanel());
|
|
assert.match(text(tree),/使用新料号/);
|
|
assert.ok(!text(tree).includes('复制元件库标签'),'part_number must not be mislabeled as Part Label');
|
|
console.log(JSON.stringify({status:'passed',cleanupEvidenceVisible:true,terminalStatusesAccurate:true,cancelActionRouted:true}));
|