const {test}=require('node:test');const assert=require('node:assert/strict');const {plan}=require('../app/static/workspace-launch.js'); const site={id:'s1'},build={id:'b1',status:'complete'}; const approved=[{build_id:'b1',state:'approved'}]; const preflight={siteId:'s1',buildId:'b1',target:'production',ready:true,message:'通过'}; const delivery={configured:{staging:true,production:true},history:[]}; const base={site,build,requests:approved,requestsKnown:true,preflight,delivery,target:'production',previewChecked:true}; test('no build cannot deploy',()=>assert.equal(plan({...base,build:null}).canDeploy,false)); test('queued build cannot deploy',()=>assert.equal(plan({...base,build:{...build,status:'queued'}}).canDeploy,false)); test('requires review before deploying',()=>assert.equal(plan({...base,previewChecked:false}).canDeploy,false)); test('requires approval from server',()=>assert.equal(plan({...base,requests:[{build_id:'b1',state:'pending'}]}).canDeploy,false)); test('no accidental cross-build approval',()=>assert.equal(plan({...base,requests:[{build_id:'b2',state:'approved'}]}).canDeploy,false)); test('cannot use preflight from another site',()=>assert.equal(plan({...base,preflight:{...preflight,siteId:'s2'}}).canDeploy,false)); test('cannot use preflight for different build',()=>assert.equal(plan({...base,preflight:{...preflight,buildId:'b2'}}).canDeploy,false)); test('cannot reuse preflight across targets',()=>assert.equal(plan({...base,target:'staging'}).canDeploy,false)); test('needs server configured deployment target',()=>assert.equal(plan({...base,delivery:{configured:{production:false}}}).canDeploy,false)); test('happy path merely enables submit; not live claim',()=>{const result=plan(base);assert.equal(result.canDeploy,true);assert.equal(result.hasRemoteRecord,false);assert.match(result.remoteDescription,/尚无/)}); test('remote record still demands public verification',()=>{const result=plan({...base,delivery:{...delivery,history:[{target:'production',build_id:'b1',release_id:'abcd'}]}});assert.equal(result.hasRemoteRecord,true);assert.match(result.remoteDescription,/访问确认/)}); test('unknown approvals are not approved',()=>assert.equal(plan({...base,requests:null}).approval,'unknown'));