const assert=require('assert'),{createHarness}=require('./harness.cjs') ;(async()=>{ const h=createHarness(),{canvasImagePath}=h.load('utils/sharing') assert.equal(canvasImagePath('pages/users/assets/fulian-logo.png','/pages/users/assets/fulian-logo.png'),'/pages/users/assets/fulian-logo.png') for(const p of ['wxfile://tmp_test','http://usr/test.png','/synthetic-user/a.png','https://example.invalid/a.png'])assert.equal(canvasImagePath(p,p),p) assert.throws(()=>canvasImagePath('')) for(const name of ['myShare','shareCard']){ const test=createHarness();test.flags.packageRelative=true const page=test.page(name),steps=[],update=page.setPosterProgress;page.setPosterProgress=function(n,s){steps.push(n);update.call(this,n,s)} page.hook('onReady');await page.startSharing();assert(page.poster&&page.cover);assert.equal(page.posterProgress,100) assert(steps.includes(45)&&steps.includes(65)&&steps.includes(75)&&steps.includes(90));assert(steps.every((n,i)=>!i||n>=steps[i-1])) const share=page.definition.onShareAppMessage.call({...page,cover:''});assert(share.imageUrl.endsWith('-share-cover.png')) } const fail=createHarness();fail.flags.packageRelative=true;fail.flags.failImageSrc='/pages/users/assets/fulian-logo.png' const page=fail.page('myShare');page.hook('onReady');await page.startSharing();assert(!page.generating);assert.equal(page.posterProgress,25);assert(page.posterError.includes('品牌图片')) const qr=createHarness();qr.flags.route=o=>o.url.endsWith('/code')?{statusCode:500,data:{}}:null const qrPage=qr.page('myShare');qrPage.hook('onReady');await qrPage.startSharing() assert(!qrPage.poster&&qrPage.cover&&qrPage.posterError);assert.equal(qrPage.posterProgress,45) console.log('PASS: package-relative path reproduction fixed for both pages; native file URI preserved; stage progress and error stop; designed share fallback.') })().catch(e=>{console.error(e.stack);process.exitCode=1})