@davoodmehraban89 / VELYQOR / commits / 1c17dcf
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(chartnova): simulate real deployed v26 HTML with slim catalog and on-demand per-symbol series

davoodmehraban89 committed Oct 15, 2026 at 14:49 UTC 1c17dcfc1b4dac8b0a2f495f540555cb29246705
1 file changed +95
scripts/test-chartnova-live-html-simulator.mjs new
+95
@@ -0,0 +1,95 @@
1 +/**
2 + * Integration test of the actual DEPLOYED v26 HTML in an ephemeral browser.
3 + *
4 + * Does not upload or deploy a Cloudflare Worker and does not modify the
5 + * live site. Only the test browser is served simulated HTML+summary JSON.
6 + */
7 +import { chromium } from 'playwright';
8 +import {patchChartNovaV26} from './patch-chartnova-v26-light-catalog.mjs';
9 +import {marketCatalogSummary} from '../packages/market-domain/src/market-catalog-summary.mjs';
10 +
11 +const ORIGIN='https://chartnova.ir/';
12 +const read=async url=>{
13 + const response=await fetch(url,{signal:AbortSignal.timeout(15000)});
14 + if(!response.ok)throw Error('public preflight '+response.status+' '+url);
15 + return response;
16 +};
17 +const [htmlResponse,catalogResponse]=await Promise.all([
18 + read(ORIGIN),read(ORIGIN+'api/markets')
19 +]);
20 +const html=await htmlResponse.text();
21 +const catalog=await catalogResponse.json();
22 +const projected=marketCatalogSummary(catalog);
23 +if(!projected.ok||projected.markets.length<40)
24 + throw Error('Missing verified live market catalog');
25 +const originalSize=JSON.stringify(catalog).length,summarySize=JSON.stringify(projected).length;
26 +if(summarySize/originalSize>=0.35)
27 + throw Error('Snapshot was not sufficiently smaller than full catalog');
28 +
29 +const syntheticV26=
30 + 'export default {async fetch(request,env){const url=new URL(request.url);'+
31 + 'const preserveOriginalBackend='+JSON.stringify('x'.repeat(41000))+';'+
32 + 'if(url.pathname==="/api/markets"&&request.method==="GET"){return Response.json({ok:true})}'+
33 + 'return new Response('+JSON.stringify(html)+
34 + ',{headers:{"content-type":"text/html; charset=utf-8"}})'+
35 + '},async scheduled(event,env){}}';
36 +const patched=patchChartNovaV26(syntheticV26);
37 +const errors=[],summaryCalls=[],marketCalls=[];
38 +const browser=await chromium.launch({headless:true});
39 +const stats={model:'staged-v26-html-in-browser',originalBytes:originalSize,summaryBytes:summarySize,
40 + savingsPercent:Math.round((1-summarySize/originalSize)*100),catalogCount:projected.markets.length};
41 +try{
42 + const context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,
43 + hasTouch:true,serviceWorkers:'block'});
44 + const page=await context.newPage();
45 + page.on('pageerror',e=>errors.push(String(e.message).slice(0,300)));
46 + await page.route(ORIGIN,route=>route.fulfill({
47 + status:200,contentType:'text/html; charset=utf-8',body:patched.newHTML
48 + }));
49 + await page.route('**/api/markets/summary',route=>{
50 + summaryCalls.push(route.request().url());
51 + return route.fulfill({status:200,contentType:'application/json',body:JSON.stringify(projected)});
52 + });
53 + await page.route('**/api/markets?symbol=*',async route=>{
54 + marketCalls.push(route.request().url());
55 + await new Promise(done=>setTimeout(done,600));
56 + await route.continue();
57 + });
58 + const response=await page.goto(ORIGIN,{waitUntil:'domcontentloaded',timeout:18000});
59 + stats.status=response?.status();
60 + await page.waitForFunction(()=>{
61 + const usd=document.getElementById('usd')?.textContent||'';
62 + const gold=document.getElementById('gold18')?.textContent||'';
63 + return usd.includes('تومان') && gold.includes('تومان');
64 + },undefined,{timeout:15000});
65 + await page.waitForFunction(()=>document.getElementById('chartbox')?.querySelector('svg'),undefined,{timeout:18000});
66 + stats.dashboard=await page.evaluate(()=>({
67 + usd:document.getElementById('usd')?.textContent,
68 + gold:document.getElementById('gold18')?.textContent,
69 + chart:!!document.getElementById('chartbox')?.querySelector('svg'),
70 + marketStatus:document.getElementById('status')?.textContent
71 + }));
72 + await page.locator('[data-nav="markets"]').first().click();
73 + stats.visibleMarkets=await page.locator('#marketgrid .marketitem').count();
74 + const eur=page.locator('#marketgrid .marketitem').filter({has:page.locator('code.ticker',{hasText:'EUR-IRT'})});
75 + if(await eur.count()){
76 + await eur.locator('button.pill').click();
77 + await page.waitForFunction(()=>{
78 + const title=document.getElementById('techTitle')?.textContent||'';
79 + const status=document.getElementById('techStatus')?.textContent||'';
80 + return title.includes('EUR-IRT')&&status.includes('نمونه ساعتی');
81 + },undefined,{timeout:16000});
82 + stats.technical=await page.locator('#techStatus').textContent();
83 + }else{
84 + throw Error('EUR-IRT not present in live verified catalog');
85 + }
86 + stats.summaryCalls=summaryCalls.length;
87 + stats.historyRequests=marketCalls.map(url=>new URL(url).searchParams.get('symbol'));
88 + stats.jsErrors=errors;
89 + await context.close();
90 +}finally{await browser.close()}
91 +console.log('CHARTNOVA_SIMULATED_V26_LAZY_MARKET '+JSON.stringify(stats));
92 +if(stats.status!==200||!stats.dashboard?.chart||stats.visibleMarkets!==projected.markets.length||
93 + stats.summaryCalls!==1||stats.historyRequests.length<2||
94 + stats.historyRequests.some(symbol=>!symbol)||errors.length)
95 + throw Error('Browser integration did not meet acceptance criteria');