// 실제 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('
');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:['