Files

23 lines
2.7 KiB
JavaScript

import assert from 'node:assert/strict';
import {WorkspaceProgress} from '../web/workspace_progress.js';
const nodes={'1':{class_type:'CheckpointLoaderSimple'},'2':{class_type:'AdachiWebUIInpaint'},'3':{class_type:'AdachiImageCompare'}};
const p=new WorkspaceProgress();p.begin(nodes);
p.handle('executing',null);
p.handle('execution_start',{prompt_id:'mine'});p.handle('progress',{prompt_id:'other',node:'2',value:9,max:10});
p.attach('mine');assert.equal(p.state,'running');assert.equal(p.value,null,'a different prompt must not set the percentage');
p.handle('executing',1);assert.equal(p.label,'Loading main model','legacy scalar node IDs remain supported');
p.handle('executing',{prompt_id:'mine',node:'1'});assert.equal(p.label,'Loading main model');assert.equal(p.max,null);
p.handle('progress',{prompt_id:'mine',node:'2',value:3,max:20});assert.equal(p.value,3);assert.equal(p.max,20);assert.match(p.label,/KSampler/);
p.handle('executing',{prompt_id:'mine',node:null});assert.equal(p.value,3,'terminal executing packets cannot reset the sampler progress');
assert.equal(p.handle('progress',{prompt_id:'other',node:'2',value:19,max:20}),false);assert.equal(p.value,3);
p.handle('progress_state',{prompt_id:'mine',nodes:{'1':{state:'finished',value:1,max:1},'2':{state:'running',value:4,max:20}}});assert.equal(p.value,4);
p.handle('executing',{prompt_id:'mine',node:'3'});assert.equal(p.value,null,'a new node cannot inherit the sampler percentage');assert.equal(p.label,'Preparing comparison images');
p.connection(false);assert.equal(p.max,null);assert.match(p.label,/Connection lost/);
p.handle('execution_success',{prompt_id:'mine'});assert.equal(p.value/p.max,1);assert.equal(p.state,'complete');
p.handle('progress',{prompt_id:'mine',node:'2',value:1,max:20});assert.equal(p.state,'complete','late packets must not regress completion');
p.begin(nodes,'error');p.handle('execution_error',{prompt_id:'error',exception_message:'missing model'});assert.equal(p.state,'error');assert.equal(p.label,'missing model');assert.equal(p.value,null);
p.begin(nodes,'cache');p.handle('execution_cached',{prompt_id:'cache',nodes:['1','2']});assert.match(p.label,/2 nodes/);assert.equal(p.value,null);
p.handle('progress_state',{prompt_id:'cache',nodes:{'2':{state:'running',value:0,max:1}}});assert.equal(p.max,null,'node-start placeholder 0/1 must remain indeterminate');
p.begin(nodes);p.handle('execution_success',{prompt_id:'fast'});p.handle('executing',null);p.attach('fast');assert.equal(p.state,'complete','legacy completion before HTTP acknowledgment must not throw');
console.log('Workspace progress: actual stage/steps, task filtering, early events, both progress protocols, cache, reconnect and late-packet safety pass');