bada-terminal / test /wrapper /batch-continuation-ui.test.cjs
VanyaJ's picture
Release BADA Terminal v2.1.0 (Enterprise Ontology, NVIDIA auto-ontology, Release Preflight)
d739b1b verified
Raw History Blame Contribute Delete
14.3 kB
// ์‹ค์ œ renderer ๋ชจ๋“ˆ์˜ ๊ฒ€ํ† ยท์Šน์ธยท์žฌ๊ฐœ ์ „๋‹ฌ ๋ฐ ๋Šฆ์€ ์‘๋‹ต ๊ฒฉ๋ฆฌ๋ฅผ ๊ฒ€์ฆํ•œ๋‹ค.
// ์„ค๋ช… ๋ฌธ์„œ: docs/specs/batch-step-continuation.md (v0.7.0, R67 ์ง„ํ–‰ ์ค‘)
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('fs'),vm=require('vm');
function dom(){const{window,document}=require('linkedom').parseHTML('<html><body></body></html>');vm.runInNewContext(fs.readFileSync('batch-continuation.js','utf8'),{window,document});return{window,document};}
const review={runId:'original',status:'reviewable',fingerprint:'a'.repeat(64),completedStepIds:['web'],remainingStepIds:['after'],costUsd:.02,loopRunId:'looprun-original',iteration:2,loopPublications:{uncertain:1,pending:0}};
for(const status of['reviewable','paused'])test('renderer identifies the retained worktree and branch before separate '+status+' action',async()=>{const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(_c,_id,input)=>{calls.push(input.action);return{success:true,review:{...review,status,workspace:{path:'/fixture/original-worktree',branch:'bada-wt-original-batch',preserved:true}}};});assert.match(document.body.textContent,/๊ฒฉ๋ฆฌ ์ž‘์—…ํด๋”: \/fixture\/original-worktree/);assert.match(document.body.textContent,/๋ธŒ๋žœ์น˜: bada-wt-original-batch/);assert.match(document.body.textContent,/์›๋ž˜ ํด๋”์™€ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์กดํ•ด ์ด์–ด๊ฐ‘๋‹ˆ๋‹ค/);assert.match(document.body.textContent,/์ƒˆ ๊ฒฉ๋ฆฌ ํด๋”๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์Šต๋‹ˆ๋‹ค/);assert.deepEqual(calls,['review']);assert.equal(document.querySelectorAll('button')[1].hidden,status==='paused');assert.equal(document.querySelectorAll('button')[2].hidden,status!=='paused');});
for(const status of['reviewable','paused'])test('renderer explains the original scheduled occurrence without enabling automatic scheduling in '+status,async()=>{const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(_c,_id,input)=>{calls.push(input.action);return{success:true,review:{...review,status,scheduledOccurrence:{due:0,timezone:'UTC',currentActive:0}}};});assert.match(document.body.textContent,/์˜ˆ์•ฝ ๋ฐœ์ƒ: 1970-01-01T00:00:00.000Z \(UTC\)/);assert.match(document.body.textContent,/์ž๋™ ์˜ˆ์•ฝ ์ƒํƒœ๋Š” ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค/);assert.match(document.body.textContent,/์ตœ์ดˆ ์˜ˆ์•ฝ ์‹คํ–‰์˜ ์‹คํŒจ ๊ธฐ๋ก์€ ๋ณด์กด/);assert.deepEqual(calls,['review']);assert.equal(document.querySelectorAll('button')[1].hidden,status==='paused');assert.equal(document.querySelectorAll('button')[2].hidden,status!=='paused');});
for(const status of['reviewable','paused'])test('renderer discloses the preserved memory continue output before explicit '+status+' action',async()=>{const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{calls.push(input.action);return{success:true,review:{...review,status,memoryContinueStepIds:['optional']}};});assert.match(document.body.textContent,/๊ณผ๊ฑฐ ๊ณ„์† ์ง„ํ–‰ ์ถœ๋ ฅ: optional/);assert.match(document.body.textContent,/๋‹น์‹œ ์†Œ๋น„๋œ ์›๋ž˜ ๊ฐ’์œผ๋กœ ๋ณด์กด/);assert.match(document.body.textContent,/์›๋ž˜ ์‹คํŒจ ์ƒํƒœ๋Š” ์œ ์ง€/);assert.deepEqual(calls,['review']);assert.equal(document.querySelectorAll('button')[1].hidden,status==='paused');assert.equal(document.querySelectorAll('button')[2].hidden,status!=='paused');});
test('blocked memory output inspection stays read-only and never enables approval from its fingerprint',async()=>{const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{calls.push(input);return input.action==='verify-continue'?{success:true,verification:{kind:'memory_continue',verifiedOutputs:2,fingerprint:'c'.repeat(64),canResume:false}}:{success:false,error:'blocked'};});const b=[...document.querySelectorAll('button')];await b.find(v=>v.textContent==='๊ณ„์† ์ง„ํ–‰ ์ถœ๋ ฅ ํ™•์ธ').onclick();assert.match(document.body.textContent,/๊ณ„์† ์ง„ํ–‰ ์ถœ๋ ฅ 2๊ฐœ/);assert.match(document.body.textContent,/๋‹น์‹œ ์†Œ๋น„๋œ ์›๋ž˜ ์ถœ๋ ฅ ๊ทธ๋Œ€๋กœ/);assert.match(document.body.textContent,/์ด์–ด๊ฐˆ ์ค€๋น„๋Š” ์•„์ง ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค/);assert.equal(b[1].hidden,true);assert.equal(b[2].hidden,true);assert.deepEqual(calls.map(v=>v.action),['review','verify-continue']);assert.equal(calls[1].fingerprint,undefined);});
test('memory output inspection ignores a response after closing its renderer',async()=>{const{window,document}=dom();let resolve;await window.openBatchContinuation('original',async(_channel,_id,input)=>input.action==='review'?{success:false,error:'blocked'}:new Promise(r=>resolve=r));const work=[...document.querySelectorAll('button')].find(v=>v.textContent==='๊ณ„์† ์ง„ํ–‰ ์ถœ๋ ฅ ํ™•์ธ').onclick();document.querySelectorAll('button')[4].onclick();resolve({success:true,verification:{kind:'memory_continue',verifiedOutputs:1,fingerprint:'c'.repeat(64)}});await work;assert.equal(document.querySelector('[role=dialog]'),null);});
test('renderer distinguishes ghost archival from partial closure and requires separate explicit preparation',async()=>{const{window,document}=dom(),actions=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{actions.push(input.action);return{success:true,review:{...review,reconciledGhostIteration:true,ghostIteration:3}};});assert.match(document.body.textContent,/์‹œ์ž‘ ๊ทผ๊ฑฐ๊ฐ€ ์—†๋Š” 3ํšŒ์ฐจ ํ–‰/);assert.match(document.body.textContent,/์Šน์ธ ์ด๋ ฅ์— ๋ณด์กดํ•˜๊ณ  ์‹คํ–‰ ์›์žฅ์—์„œ ์ œ์™ธ/);assert.match(document.body.textContent,/๋‹ค์Œ ํšŒ์ฐจ๋Š” ์ƒˆ๋กœ ์‹œ์ž‘/);assert.doesNotMatch(document.body.textContent,/๋ถ€๋ถ„ ๋งˆ๊ฐ ํ–‰/);assert.deepEqual(actions,['review']);assert.equal(document.querySelectorAll('button')[2].hidden,true);});
test('renderer discloses independent partial-row reconciliation and preserved originals before any acceptance',async()=>{const{window,document}=dom(),actions=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{actions.push(input.action);return{success:true,review:{...review,reconciledLoopRows:true}};});assert.match(document.body.textContent,/๋…๋ฆฝ ๊ด€์ธก๊ณผ ๋Œ€์‚ฌํ•œ ๋ถ€๋ถ„ ๋งˆ๊ฐ ํ–‰/);assert.match(document.body.textContent,/์›๋ž˜ ํ–‰์€ ์Šน์ธ ๊ธฐ๋ก์— ๋ณด์กด/);assert.deepEqual(actions,['review']);assert.equal(document.querySelectorAll('button')[2].hidden,true);});
test('renderer names the reconstructed record and discloses intentional loop work, while settlement verification stays read-only',async()=>{const{window,document}=dom();await window.openBatchContinuation('original',async()=>({success:true,review:{...review,reconstructedPhase:true,reconstructedPhaseName:'๋ชฉํ‘œ ํ‰๊ฐ€'}}));assert.match(document.body.textContent,/์›๋ž˜ ๊ด€์ธก์œผ๋กœ ๋ณต์›ํ•  ๊ธฐ๋ก: ๋ชฉํ‘œ ํ‰๊ฐ€/);assert.match(document.body.textContent,/ํ›„์† ๋ถ„์„ยท๋‹ค์Œ ํšŒ์ฐจ/);document.querySelector('[role=dialog]').parentElement.remove();const calls=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{calls.push(input.action);return input.action==='verify'?{success:true,verification:{kind:'settlement',fingerprint:'b'.repeat(64),canResume:false}}:{success:false,error:'blocked'};});await [...document.querySelectorAll('button')].find(b=>b.textContent==='์›๋ž˜ ๊ด€์ธก ํ™•์ธ').onclick();assert.match(document.body.textContent,/ํšŒ์ฐจ ์ •์‚ฐ ๊ด€์ธก/);assert.doesNotMatch(document.body.textContent,/undefined/);assert.equal(document.querySelectorAll('button')[1].hidden,true);assert.equal(document.querySelectorAll('button')[2].hidden,true);assert.deepEqual(calls,['review','verify']);});
test('blocked renderer exposes read-only evidence verification and never turns its fingerprint into a resume approval',async()=>{const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(...args)=>{calls.push(args);return args[2].action==='verify'?{success:true,verification:{kind:'evaluation',goalMet:true,verifiedGoals:6,fingerprint:'b'.repeat(64),canResume:false}}:{success:false,error:'์ €์žฅ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.'};});const buttons=[...document.querySelectorAll('button')],verify=buttons.find(b=>b.textContent==='์›๋ž˜ ๊ด€์ธก ํ™•์ธ');assert.ok(verify);assert.equal(verify.hidden,false);await verify.onclick();assert.match(document.body.textContent,/๋ชฉํ‘œ ๊ด€์ธก 6๊ฐœ/);assert.match(document.body.textContent,/์ด์–ด๊ฐˆ ์ค€๋น„๋Š” ์•„์ง ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค/);assert.equal(buttons[1].hidden,true);assert.equal(buttons[2].hidden,true);assert.deepEqual(calls.map(c=>c[2].action),['review','verify']);assert.equal(calls[1][2].fingerprint,undefined);});
test('a closed renderer ignores a late read verification response',async()=>{const{window,document}=dom();let resolve;await window.openBatchContinuation('original',async(_channel,_id,input)=>input.action==='review'?{success:false,error:'blocked'}:new Promise(r=>resolve=r));const verify=[...document.querySelectorAll('button')].find(b=>b.textContent==='์›๋ž˜ ๊ด€์ธก ํ™•์ธ');assert.ok(verify);const pending=verify.onclick();document.querySelector('[role="dialog"]').parentElement.remove();resolve({success:true,verification:{kind:'analysis',verifiedRequests:1,fingerprint:'b'.repeat(64),canResume:false}});await pending;assert.equal(document.querySelector('[role="dialog"]'),null);});
test('the renderer prepares then separately resumes with the reviewed fingerprint, without result HTML',async()=>{
const{window,document}=dom(),calls=[];let status='reviewable',refreshes=0;await window.openBatchContinuation('original',async(...args)=>{calls.push(args);const action=args[2].action;if(action==='review')return{success:true,review:{...review,status,completedStepIds:['<img src=x onerror=alert(1)>']}};if(action==='accept')status='paused';return{success:true};},()=>{refreshes++;});
const buttons=[...document.querySelectorAll('button')];assert.match(document.body.textContent,/<img src=x/);assert.equal(document.querySelector('img'),null);assert.match(document.body.textContent,/์ด์–ด๊ฐˆ ํšŒ์ฐจ: 2/);assert.match(document.body.textContent,/์•Œ๋ฆผ ์ œ์ถœ ๋ฏธํ™•์ธ: 1๊ฑด/);assert.match(document.body.textContent,/ํ™•์ธ ๋น„์šฉ: \$0.02/);assert.equal(buttons[1].hidden,false);assert.equal(buttons[2].hidden,true);
await buttons[1].onclick();assert.equal(calls.length,2);assert.equal(calls[1][2].action,'accept');assert.equal(calls[1][2].fingerprint,review.fingerprint);assert.equal(refreshes,1);
await buttons[0].onclick();assert.equal(buttons[2].hidden,false);await buttons[2].onclick();assert.equal(calls[3][2].action,'resume');assert.equal(refreshes,2);assert.match(document.body.textContent,/์›๋ž˜ ๋ฐฐ์น˜๊ฐ€ ์™„๋ฃŒ/);buttons[4].onclick();assert.equal(document.querySelector('[role=dialog]'),null);
});
test('closing a pending review prevents a late response from attaching evidence',async()=>{
const{window,document}=dom();let release;const pending=window.openBatchContinuation('original',()=>new Promise(r=>{release=r;}));document.querySelectorAll('button')[4].onclick();release({success:false,error:'LATE_PRIVATE_DETAIL'});await pending;assert.equal(document.querySelector('[role=dialog]'),null);assert.doesNotMatch(document.body.textContent,/LATE_PRIVATE_DETAIL/);
});
test('an older overlapping review cannot replace a newer fingerprint or enabled action',async()=>{
const{window,document}=dom();let release;const pending=window.openBatchContinuation('original',()=>new Promise(r=>{release=r;})),first=release;const second=document.querySelector('button').onclick();release({success:true,review:{...review,status:'paused',fingerprint:'b'.repeat(64)}});await second;first({success:true,review});await pending;assert.match(document.body.textContent,/b{64}/);assert.doesNotMatch(document.body.textContent,/a{64}/);assert.equal(document.querySelectorAll('button')[2].hidden,false);
});
test('a blocked prepared review offers explicit revoke with its own fingerprint and no resume action',async()=>{
const{window,document}=dom(),calls=[];await window.openBatchContinuation('original',async(...args)=>{calls.push(args);return args[2].action==='review'?{success:true,review:{...review,status:'paused',canResume:false,canRevoke:true,revokeFingerprint:'c'.repeat(64)}}:{success:true};});
const buttons=[...document.querySelectorAll('button')];assert.equal(buttons[2].hidden,true);assert.equal(buttons[3].hidden,false);await buttons[3].onclick();assert.equal(calls[1][2].action,'revoke');assert.equal(calls[1][2].fingerprint,'c'.repeat(64));assert.match(document.body.textContent,/๊ธฐ์กด ์™ธ๋ถ€ ํšจ๊ณผ์™€ ์‹คํ–‰ ๊ธฐ๋ก์€ ๋ณด์กด/);assert.equal(calls.some(c=>c[2].action==='resume'),false);
});
for(const archivedFirstRow of [true,false])test('renderer discloses the first real start '+(archivedFirstRow?'with preserved original row':'without inventing an original row'),async()=>{const{window,document}=dom(),actions=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{actions.push(input.action);return{success:true,review:{...review,iteration:1,completedStepIds:[],remainingStepIds:['child'],reconciledFirstIteration:true,archivedFirstRow}};});assert.match(document.body.textContent,/์ฒซ ํšŒ์ฐจ ์‹คํ–‰ ์ „ ๊ธฐ๋ก๊ณผ ์›๋ž˜ ์˜ˆ์‚ฐ/);assert.match(document.body.textContent,/1ํšŒ์ฐจ๋ฅผ ์ƒˆ๋กœ ์‹œ์ž‘/);if(archivedFirstRow)assert.match(document.body.textContent,/์›๋ž˜ 1ํšŒ์ฐจ ํ–‰์€ ์Šน์ธ ์ด๋ ฅ์— ๋ณด์กด/);else assert.doesNotMatch(document.body.textContent,/์›๋ž˜ 1ํšŒ์ฐจ ํ–‰/);assert.doesNotMatch(document.body.textContent,/์ง์ „ ์™„๋ฃŒ ํšŒ์ฐจ|๋ถ€๋ถ„ ๋งˆ๊ฐ ํ–‰/);assert.deepEqual(actions,['review']);assert.equal(document.querySelectorAll('button')[2].hidden,true);});
for(const phase of ['evaluated','analyzed','settled'])test('renderer names partial '+phase+' evidence without preparing or resuming automatically',async()=>{const{window,document}=dom(),actions=[];await window.openBatchContinuation('original',async(_channel,_id,input)=>{actions.push(input.action);return{success:true,review:{...review,reconciledLoopRows:true,reconciledLoopPhase:phase}};});assert.match(document.body.textContent,new RegExp('๋ถ€๋ถ„ ๋งˆ๊ฐ ๊ธฐ์ค€: '+({evaluated:'๋ชฉํ‘œ ํ‰๊ฐ€',analyzed:'๋ฉ”ํƒ€ ๋ถ„์„',settled:'ํšŒ์ฐจ ์ •์‚ฐ'})[phase]));assert.match(document.body.textContent,/์›๋ž˜ ํ–‰์€ ์Šน์ธ ๊ธฐ๋ก์— ๋ณด์กด/);assert.deepEqual(actions,['review']);assert.equal(document.querySelectorAll('button')[2].hidden,true);});