Files
aigen/tests/studio2-queue-view.test.mjs
T
TowstyandCursor 99b61e67d7 Keep Enhance + Generate as one queue row with shared progress.
The PE stage now stays on the same jobId so the header and queue badge agree, and jobs behind it do not promote when enhance finishes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-26 14:42:22 -05:00

33 lines
2.4 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import {queueJobs,jobView,elapsedSeconds,jobStageLabel,jobProgressView} from '../shared/studio2/queue-view.mjs'
test('queue shows every waiting job in order alongside the running job',()=>{
const jobs=[{id:'late',state:'waiting',queuedAt:30},{id:'done',state:'complete',queuedAt:1},{id:'early',state:'waiting',queuedAt:10},{id:'active',state:'rendering',queuedAt:20},{id:'held',state:'held',queuedAt:40}]
assert.deepEqual(queueJobs(jobs).map(j=>j.id),['active','early','late','held'])
assert.equal(queueJobs(Array.from({length:15},(_,i)=>({id:i,state:'waiting',queuedAt:i}))).length,15)
})
test('enhancing stays on the active queue with the same job id as generate',()=>{
const pe={id:'one',state:'enhancing',queuedAt:10}
const behind={id:'two',state:'waiting',queuedAt:20}
assert.deepEqual(queueJobs([behind,pe]).map(j=>j.id),['one','two'])
assert.equal(jobStageLabel('enhancing'),'Enhancing prompt…')
assert.equal(jobStageLabel('rendering'),'Generating…')
assert.equal(jobStageLabel('submitting'),'Generating…')
assert.deepEqual(jobProgressView(pe),{indeterminate:true,percent:null})
assert.deepEqual(jobProgressView({state:'enhancing',progress:{step:2,maxStep:4,percent:50}}),{indeterminate:false,percent:50})
assert.deepEqual(jobProgressView({state:'rendering',progress:{step:3,maxStep:6,percent:50}}),{indeterminate:false,percent:50})
assert.equal(jobProgressView({state:'waiting'}),null)
// PE → generate is a stage change on the same row, not a vanish frame
const same=[{id:'one',state:'submitting',queuedAt:10},{id:'two',state:'waiting',queuedAt:20}]
assert.deepEqual(queueJobs(same).map(j=>j.id),['one','two'])
})
test('authoritative completion ends a stale rendering row and freezes its timer',()=>{
const record={state:'rendering',queuedAt:1000,startedAt:2000,updatedAt:5000}
for(const status of ['complete','error','cancelled']){
const result=jobView(record,{status,updatedAt:12000});assert.equal(elapsedSeconds(result,20000),10);assert.equal(elapsedSeconds(result,2000000),10);assert.equal(queueJobs([result]).length,0)
}
const live=jobView(record,null,{status:'complete'});assert.equal(live.state,'complete');assert.equal(elapsedSeconds(live,999999),3)
assert.equal(jobView(record,null,{status:'complete',saving:true}).state,'rendering')
assert.equal(elapsedSeconds({state:'complete',startedAt:2000,finishedAt:12000,updatedAt:200000},500000),10)
})