@davoodmehraban89 / VELYQOR / commits / 9fe4094
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(incident): isolate original v27 SW offline recovery and artificially corrupted browser cache

davoodmehraban89 committed Oct 15, 2026 at 19:34 UTC 9fe4094002171f12f1e7314628aa005385aa3be0
1 file changed +55
scripts/diagnose-chartnova-v27-sw-cache.mjs new
+55
@@ -0,0 +1,55 @@
1 +/**
2 + * Isolated v27 ORIGINAL Service Worker offline cache behavior.
3 + * Real / and /sw.js are obtained via read-only GET; all REST API calls mocked.
4 + * Poisoning cache is restricted to a throwaway Playwright browser profile and
5 + * demonstrates a possible failure mechanism, not the user's actual root cause.
6 + */
7 +import {chromium} from 'playwright';
8 +const host='https://2cbeb4e2-velyqor-preview.davoodmehraban89.workers.dev/';
9 +const check=async path=>{
10 + const r=await fetch(host+path,{signal:AbortSignal.timeout(15000)});
11 + if(!r.ok)throw Error('Cannot get read-only '+path+' '+r.status);
12 + return r.text();
13 +};
14 +const [html,sw]=await Promise.all([check(''),check('sw.js')]);
15 +if(!sw.includes("caches.match('/')")||!sw.includes("chartnova-v1"))
16 + throw Error('Actual versioned SW script differs from expected cached navigation strategy');
17 +const browser=await chromium.launch({headless:true});
18 +const report={scenario:'actual_v27_service_worker_offline_and_artificial_poison',versionUrl:host,actualSWBytes:sw.length};
19 +try{
20 + const ctx=await browser.newContext({viewport:{width:390,height:844},isMobile:true,serviceWorkers:'allow'});
21 + await ctx.route('**/api/**',r=>r.fulfill({status:503,contentType:'application/json',body:'{"ok":false,"error":"STAGING_ONLY"}'}));
22 + await ctx.route(host,r=>r.fulfill({status:200,contentType:'text/html; charset=utf-8',body:html}));
23 + await ctx.route('**/sw.js',r=>r.fulfill({status:200,contentType:'application/javascript',body:sw}));
24 + // Cache installation assets; no request to production and no provider/DB mutation.
25 + await ctx.route('**/icon.svg',r=>r.fulfill({status:200,contentType:'image/svg+xml',body:'<svg xmlns="http://www.w3.org/2000/svg"/>'}));
26 + await ctx.route('**/manifest.webmanifest',r=>r.fulfill({status:200,contentType:'application/manifest+json',body:'{"name":"ChartNova Preview","start_url":"/"}'}));
27 + const page=await ctx.newPage();
28 + const exceptions=[];
29 + page.on('pageerror',e=>exceptions.push(String(e.message).slice(0,200)));
30 + await page.goto(host,{waitUntil:'domcontentloaded',timeout:20000});
31 + await page.waitForFunction(()=>!!navigator.serviceWorker?.controller,undefined,{timeout:12000});
32 + await page.waitForFunction(async()=> (await caches.keys()).includes('chartnova-v1'),undefined,{timeout:12000});
33 + await ctx.setOffline(true);
34 + await page.reload({waitUntil:'domcontentloaded',timeout:16000});
35 + report.validCachedOfflineVisible=await page.evaluate(()=>!!document.querySelector('.shell')&&
36 + document.querySelector('.shell').getBoundingClientRect().width>80);
37 + // Artificially corrupt *only the ephemeral browser cache*, never any real user cache.
38 + await page.evaluate(async()=>{
39 + const c=await caches.open('chartnova-v1');
40 + await c.put('/',new Response('<!doctype html><html><head><title>TEST-CORRUPT</title></head><body style="background:#000"></body></html>',{headers:{'content-type':'text/html; charset=utf-8'}}));
41 + });
42 + await page.reload({waitUntil:'domcontentloaded',timeout:16000});
43 + report.artificialBadCachedOfflineBlank=await page.evaluate(()=>
44 + document.title==='TEST-CORRUPT'&&!document.querySelector('.shell')&&
45 + (document.body?.innerText.length??0)===0);
46 + await ctx.setOffline(false);
47 + await page.reload({waitUntil:'domcontentloaded',timeout:16000});
48 + report.onlineRecoveredVisible=await page.evaluate(()=>
49 + !!document.querySelector('.shell')&&document.querySelector('.shell').getBoundingClientRect().width>80);
50 + report.pageErrors=exceptions;
51 + await ctx.close();
52 +}finally{await browser.close()}
53 +console.log('CHARTNOVA_V27_REAL_SW_CACHE_TEST '+JSON.stringify(report));
54 +if(!report.validCachedOfflineVisible||!report.artificialBadCachedOfflineBlank||
55 + !report.onlineRecoveredVisible||report.pageErrors.length)process.exitCode=1;