// 실패 intent는 불변으로 두고, continue 정책이 실제 게시한 출력만 별도로 보존한다. // 설명 문서: docs/specs/batch-step-continuation.md (v0.18.0, R67 진행 중) const {hash,hex}=require('../services/bong-browser-resolution'),{same}=require('./batch-recovery-record'); const fail=()=>require('./batch-checkpoint-record').fail(); const uncertain=error=>require('../utils/cli-storage-error').isUncertainCliFailure({...error,retryable:false}); function resolved(record,key){return record.continuations?.[key]||require('./batch-memory-continue-record').resolved(record,key);} function validate(record){ const map=record.continuations;if(map===undefined)return; if(!map||typeof map!=='object'||Array.isArray(map)||!Object.keys(map).length||Object.keys(map).length>4096)fail(); const revisions=new Set(),steps=require('./batch-checkpoint-record').stepsFor({steps:record.definition.steps}); for(const [key,r]of Object.entries(map)){ const e=record.entries[key],keys=['version','kind','entryKey','originalEntryHash','recordedRevision','recordedAt','output','outputHash','usageIds','requestKeys','usageHash','invocationsHash']; const list=v=>Array.isArray(v)&&v.length<=4096&&new Set(v).size===v.length&&v.every(k=>typeof k==='string'&&k.length>0&&k.length<=512&&!['__proto__','constructor','prototype'].includes(k)); if(r?.version!==1||r.kind!=='continued'||r.entryKey!==key||e?.status!=='failed'||steps[e.stepIndex]?.on_failure!=='continue'||uncertain(e.error) ||Object.keys(r).length!==keys.length||Object.keys(r).some(k=>!keys.includes(k))||!['originalEntryHash','outputHash','usageHash','invocationsHash'].every(k=>hex(r[k]))||hash(e)!==r.originalEntryHash||hash(r.output)!==r.outputHash ||!Number.isSafeInteger(r.recordedRevision)||r.recordedRevision<3||r.recordedRevision>record.revision||revisions.has(r.recordedRevision)||!Number.isFinite(Date.parse(r.recordedAt))||Date.parse(r.recordedAt)!Object.hasOwn(old,k)); for(const [k,v]of Object.entries(old))if(!same(v,actual[k]))fail(); if(added.length){if(added.length!==1||added[0]!==previous.currentKey||actual[added[0]].recordedRevision!==previous.revision+1)fail();return true;} if(!same(old,actual))fail();return false; } module.exports={resolved,validate,transition,uncertain};