Intelligence, Advanced Charting & Trading Platform
diagnostics/chartnova-stage2-v27-preview-2026-10-15
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 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 | for(let attempt=0;attempt<3;attempt++){ |
| 11 | try{const r=await fetch(host+path,{signal:AbortSignal.timeout(18000)});if(r.ok)return r.text();} |
| 12 | catch(e){if(attempt===2)throw Error('staged_SW_network_unavailable_after_3_attempts');} |
| 13 | if(attempt<2)await new Promise(done=>setTimeout(done,1000*(attempt+1))); |
| 14 | } |
| 15 | throw Error('staged_SW_HTTP_unavailable_after_retries'); |
| 16 | }; |
| 17 | const [html,sw]=await Promise.all([check(''),check('sw.js')]); |
| 18 | if(!sw.includes("caches.match('/')")||!sw.includes("chartnova-v1")) |
| 19 | throw Error('Actual versioned SW script differs from expected cached navigation strategy'); |
| 20 | const browser=await chromium.launch({headless:true}); |
| 21 | const report={scenario:'actual_v27_service_worker_offline_and_artificial_poison',versionUrl:host,actualSWBytes:sw.length}; |
| 22 | try{ |
| 23 | const ctx=await browser.newContext({viewport:{width:390,height:844},isMobile:true,serviceWorkers:'allow'}); |
| 24 | await ctx.route('**/api/**',r=>r.fulfill({status:503,contentType:'application/json',body:'{"ok":false,"error":"STAGING_ONLY"}'})); |
| 25 | let simulateOffline=false; |
| 26 | await ctx.route(host,r=>simulateOffline?r.abort('internetdisconnected'):r.fulfill({status:200,contentType:'text/html; charset=utf-8',body:html})); |
| 27 | await ctx.route('**/sw.js',r=>r.fulfill({status:200,contentType:'application/javascript',body:sw})); |
| 28 | // Cache installation assets; no request to production and no provider/DB mutation. |
| 29 | await ctx.route('**/icon.svg',r=>r.fulfill({status:200,contentType:'image/svg+xml',body:'<svg xmlns="http://www.w3.org/2000/svg"/>'})); |
| 30 | await ctx.route('**/manifest.webmanifest',r=>r.fulfill({status:200,contentType:'application/manifest+json',body:'{"name":"ChartNova Preview","start_url":"/"}'})); |
| 31 | const page=await ctx.newPage(); |
| 32 | const exceptions=[]; |
| 33 | page.on('pageerror',e=>exceptions.push(String(e.message).slice(0,200))); |
| 34 | await page.goto(host,{waitUntil:'domcontentloaded',timeout:20000}); |
| 35 | await page.waitForFunction(()=>!!navigator.serviceWorker?.controller,undefined,{timeout:12000}); |
| 36 | await page.waitForFunction(async()=> (await caches.keys()).includes('chartnova-v1'),undefined,{timeout:12000}); |
| 37 | simulateOffline=true; |
| 38 | await ctx.setOffline(true); |
| 39 | await page.reload({waitUntil:'domcontentloaded',timeout:16000}); |
| 40 | report.validCachedOfflineVisible=await page.evaluate(()=>!!document.querySelector('.shell')&& |
| 41 | document.querySelector('.shell').getBoundingClientRect().width>80); |
| 42 | // Artificially corrupt *only the ephemeral browser cache*, never any real user cache. |
| 43 | await page.evaluate(async()=>{ |
| 44 | const c=await caches.open('chartnova-v1'); |
| 45 | 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'}})); |
| 46 | }); |
| 47 | await page.reload({waitUntil:'domcontentloaded',timeout:16000}); |
| 48 | report.artificialBadCachedOfflineBlank=await page.evaluate(()=> |
| 49 | document.title==='TEST-CORRUPT'&&!document.querySelector('.shell')&& |
| 50 | (document.body?.innerText.length??0)===0); |
| 51 | await ctx.setOffline(false); |
| 52 | simulateOffline=false; |
| 53 | await page.reload({waitUntil:'domcontentloaded',timeout:16000}); |
| 54 | report.onlineRecoveredVisible=await page.evaluate(()=> |
| 55 | !!document.querySelector('.shell')&&document.querySelector('.shell').getBoundingClientRect().width>80); |
| 56 | report.pageErrors=exceptions; |
| 57 | await ctx.close(); |
| 58 | }finally{await browser.close()} |
| 59 | console.log('CHARTNOVA_V27_REAL_SW_CACHE_TEST '+JSON.stringify(report)); |
| 60 | if(!report.validCachedOfflineVisible||!report.artificialBadCachedOfflineBlank|| |
| 61 | !report.onlineRecoveredVisible||report.pageErrors.length)process.exitCode=1; |