Intelligence, Advanced Charting & Trading Platform

1 /**
2 * Version-specific read-only public-asset parity diagnostic.
3 * No production or Cloudflare API mutation; hashes PUBLIC frontend assets only.
4 * v26 and v27 Preview are separate ephemeral origins, not production deployment.
5 */
6 import {createHash} from 'node:crypto';
7 import {Script} from 'node:vm';
8 const workers=[
9 {label:'v26',url:'https://85177f9d-velyqor-preview.davoodmehraban89.workers.dev/'},
10 {label:'v27',url:'https://2cbeb4e2-velyqor-preview.davoodmehraban89.workers.dev/'}
11 ];
12 async function safeGet(url){
13 for(let n=0;n<3;n++){
14 try{
15 const result=await fetch(url,{signal:AbortSignal.timeout(16000)});
16 if(result.ok) return result.text();
17 }catch{}
18 if(n<2)await new Promise(resolve=>setTimeout(resolve,(n+1)*700));
19 }
20 throw Error('PUBLIC_ASSET_UNAVAILABLE');
21 }
22 function hash(s){return createHash('sha256').update(s,'utf8').digest('hex')}
23 function scriptFrom(html){
24 const scripts=[...html.matchAll(/<script>([\s\S]*?)<\/script>/g)];
25 if(scripts.length!==1)throw Error('Unexpected number of inline scripts');
26 new Script(scripts[0][1]);
27 return scripts[0][1];
28 }
29 const assets=await Promise.all(workers.map(async w=>{
30 const [html,sw]=await Promise.all([safeGet(w.url),safeGet(w.url+'sw.js')]);
31 const script=scriptFrom(html);
32 if(!html.includes('class="shell"')||!sw.includes('chartnova-v1'))throw Error('Unexpected app asset');
33 return {
34 label:w.label,url:w.url,html,sw,script,
35 hash:{html:hash(html),sw:hash(sw),inlineJS:hash(script)},
36 bytes:{html:Buffer.byteLength(html),sw:Buffer.byteLength(sw),script:Buffer.byteLength(script)}
37 };
38 }));
39 const [v26,v27]=assets;
40 const stripScript=h=>h.replace(/<script>[\s\S]*?<\/script>/,
41 '<script>__INLINE_JS_VERSION_SLOT__</script>');
42 const outerEqual=stripScript(v26.html)===stripScript(v27.html);
43 const swEqual=v26.sw===v27.sw;
44 const expectedPatch=v27.script.includes('chartnovaRefreshInFlight')&&
45 !v26.script.includes('chartnovaRefreshInFlight');
46 const result={
47 verdict:swEqual&&outerEqual&&expectedPatch?'FRONTEND_SCOPE_CONFIRMED':'DIFFERENCE_REQUIRES_REVIEW',
48 liveDeploymentNotChanged:true,
49 originalWorkerBackendNotCompared:true,
50 previewVersions:assets.map(({label,url,hash,bytes})=>({label,url,sha256:hash,bytes})),
51 serviceWorkerByteIdentical:swEqual,
52 htmlOutsideInlineJavascriptIdentical:outerEqual,
53 expectedJavascriptPatchMarker:expectedPatch
54 };
55 console.log('CHARTNOVA_V26_V27_PUBLIC_ASSET_DIFF '+JSON.stringify(result));
56 if(!swEqual||!outerEqual||!expectedPatch)process.exitCode=1;