import test from 'node:test' import assert from 'node:assert/strict' import { desktopProjectBody } from '../lib/desktop-client/contract.mjs' const digest = 'a'.repeat(64) const fixture = () => ({ revision: 1, status: 'draft', document: { version: 3, id: 'native-test', name: '完整模板', native: { format: 'photocraft', schemaVersion: 1, documentSource: 'native:'+digest, files: ['canvas.pcraft','context.json','session-backup.json'].map(path=>({path,source:'native:'+digest,sha256:digest,size:100})) }, screens: Array.from({length:22},(_,i)=>({id:'s'+i,width:1440,height:i===21?2830:2100,previewSource:'local:preview-'+i})) } }) test('preserves production native cloud long canvas and legacy geometry limits',()=>{ const saved=desktopProjectBody(fixture()); assert.equal(saved.document.screens.length,22); assert.equal(saved.document.screens.reduce((s,r)=>s+r.height,0),46930) for(const version of [1,2]){const body=fixture();body.document.version=version;assert.throws(()=>desktopProjectBody(body))} for(const height of [0,4609]){const body=fixture();body.document.screens[0].height=height;assert.throws(()=>desktopProjectBody(body))} const tooTall=fixture();tooTall.document.screens=Array.from({length:101},(_,i)=>({id:'s'+i,width:1440,height:3000}));assert.throws(()=>desktopProjectBody(tooTall)) const tooMany=fixture();tooMany.document.screens=Array.from({length:129},(_,i)=>({id:'s'+i,width:1440,height:400}));assert.throws(()=>desktopProjectBody(tooMany)) const tooLarge=fixture();tooLarge.document.native.files[0].size=512*1024*1024+1;assert.throws(()=>desktopProjectBody(tooLarge)) }) test('preserves forty native creation warnings without weakening forty-one boundary',()=>{ const body=fixture();body.document.screens=body.document.screens.slice(0,1);body.status='completed' body.document.creation={creationRevision:0,brief:{source:'upload',name:'',brandId:'',brandName:'',categoryId:'',categoryName:'',identifierType:'sku',identifier:'',variant:'',colorMaterialId:'',colorName:'',dimensions:{length:'',width:'',height:'',unit:'mm'},images:[],note:''},facts:{status:'idle',items:[],missing:[]},sellingPoints:{batches:[],selected:[],direction:'',stale:false},plan:{status:'idle',screens:[],invalidReason:'',confirmedAt:null,confirmedRevision:null},designSnapshot:null} const warnings=Array.from({length:40},(_,i)=>'待确认'+i);body.document.creation.sellingPoints.batches=[{id:'batch-1',direction:'',items:['保留原文'],warnings}];body.document.creation.plan.warnings=warnings const saved=desktopProjectBody(body);assert.equal(saved.document.creation.sellingPoints.batches[0].warnings.length,40);assert.equal(saved.document.creation.plan.warnings.length,40) for(const target of [body.document.creation.sellingPoints.batches[0],body.document.creation.plan]){target.warnings=[...warnings,'第41条'];assert.throws(()=>desktopProjectBody(body));target.warnings=warnings} })