11import os
22import json
3+ import re
34import subprocess
45import tempfile
56import unittest
7+ import urllib .request
68from pathlib import Path
79from unittest .mock import patch
810
1315
1416
1517class BrowserExecutableTests (unittest .TestCase ):
18+ def test_actual_system_fixture_joins_modules_without_startup_preloads (self ):
19+ with browser_smoke .serve (browser_smoke .WEB ) as base :
20+ with urllib .request .urlopen (base + '/__smoke_orrery.html' , timeout = 5 ) as response :
21+ html = response .read ().decode ('utf-8' )
22+ match = re .search (r'<script>(.*?)</script>' , html , re .S )
23+ self .assertIsNotNone (match )
24+ with tempfile .TemporaryDirectory () as temp :
25+ fixture = Path (temp ) / 'fixture.js'
26+ fixture .write_text (match .group (1 ), encoding = 'utf-8' )
27+ script = r"""
28+ import fs from 'node:fs';import assert from 'node:assert/strict';
29+ const source=fs.readFileSync(process.argv[1],'utf8').replaceAll('import(', 'mockImport(');
30+ const callbacks=new Map(),calls=[],origin='http://127.0.0.1:8123';
31+ const app=origin+'/sol/releases/fixture/app.js?v=fixture';
32+ const moduleUrls=JSON.parse(source.match(/const smokeModuleUrls = (\[[^;]+\]);/)[1]);
33+ const entries=moduleUrls.map(url=>({name:new URL(url,origin+'/sol/releases/fixture/__smoke_orrery.html').href}));
34+ const body={dataset:{surface:'today',viewCode:'ready',viewCodeName:'observe'}};
35+ const tab={click(){calls.push('native-orrery-click');body.dataset.surface='orrery';body.dataset.viewCodeName='orrery';},getAttribute(){return body.dataset.surface==='orrery'?'true':'false';}};
36+ const document={body,querySelector(selector){
37+ if(selector.startsWith('link['))return null;
38+ if(selector.includes('script'))return {src:app};
39+ if(selector.includes('data-mode="orrery"'))return tab;
40+ return null;
41+ }};
42+ const modules={'store.js':{store:{orrery:{}}},'orreryTime.js':{},'orrery.js':{enterOrrery:async()=>{}},'moons.js':{MOONS:[{el:[[1]]}]}};
43+ const mockImport=async url=>{calls.push(url);assert.ok(entries.some(entry=>entry.name===url),'join the URL actually fetched by the app');return modules[new URL(url).pathname.split('/').at(-1)];};
44+ const run=new Function('document','location','performance','localStorage','addEventListener','setInterval','requestAnimationFrame','mockImport',source);
45+ run(document,{origin,href:origin+'/sol/releases/fixture/__smoke_orrery.html'},
46+ {now:()=>0,getEntriesByType:()=>entries},{setItem(){}},(type,fn)=>callbacks.set(type,fn),()=>{},()=>{},mockImport);
47+ await callbacks.get('load')();for(let i=0;i<20;i++)await Promise.resolve();
48+ assert.equal(calls[0],'native-orrery-click','deferred System must enter through its actual control');
49+ assert.deepEqual(calls.slice(1),entries.map(entry=>entry.name),'reuse all four actual loaded module identities');
50+ assert.equal(body.dataset.smokeMode,'yes');assert.equal(body.dataset.smokeErrs,undefined);
51+ """
52+ result = subprocess .run (['node' , '--input-type=module' , '-e' , script , str (fixture )],
53+ text = True , capture_output = True , timeout = 10 , check = False )
54+ self .assertEqual (result .returncode , 0 , result .stderr )
55+
1656 def test_actual_driver_verifies_observe_before_native_research_entry (self ):
1757 script = r"""
1858import fs from 'node:fs'; import assert from 'node:assert/strict';
1959const source=fs.readFileSync(process.argv[1],'utf8').replace('import puppeteer from "puppeteer-core";','');
2060const AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;
21- for(const broken of ['', 'image', 'observation-hidden', 'capture-time', 'source', 'research-entry', 'model-base', 'canvas', 'regions', 'schema']) {
61+ for(const broken of ['', 'legacy-schema', ' image', 'observation-hidden', 'capture-time', 'source', 'research-entry', 'model-base', 'canvas', 'regions', 'schema', 'fallback-schema', 'older-schema', 'future- schema']) {
2262 const calls=[]; let output='';
2363 const node=(text='')=>({textContent:text,hidden:false,getClientRects(){return this.hidden?[]:[{}];},getAttribute(){return 'true';}});
2464 const elements={solarObservation:node(), observationImage:{...node(),complete:true,naturalWidth:1024},
@@ -33,6 +73,10 @@ def test_actual_driver_verifies_observe_before_native_research_entry(self):
3373 if(broken==='source')elements.observationSource.href='';
3474 if(broken==='canvas')elements.solarCanvas.hidden=true;
3575 if(broken==='schema')elements.schemaVersion.textContent='Loading snapshot.';
76+ if(broken==='fallback-schema')elements.schemaVersion.textContent='solar-state-snapshot.v1';
77+ if(broken==='older-schema')elements.schemaVersion.textContent='solar-state-snapshot.v2';
78+ if(broken==='future-schema')elements.schemaVersion.textContent='solar-state-snapshot.v4';
79+ if(broken==='legacy-schema')elements.schemaVersion.textContent='solar-state-snapshot.v2';
3680 const page={setViewport:async()=>{},setBypassServiceWorker:async()=>{},on(){},
3781 createCDPSession:async()=>({send:async()=>{}}),goto:async()=>{},
3882 async waitForFunction(predicate,options,...args){
@@ -50,11 +94,12 @@ def test_actual_driver_verifies_observe_before_native_research_entry(self):
5094 };
5195 const browser={newPage:async()=>page,close:async()=>{calls.push('close');},disconnect(){},process(){throw new Error('unexpected kill');}};
5296 const processMock={argv:['node','driver','fixture-browser','http://127.0.0.1/sol/releases/fixture/index.html'],stdout:{write(value){output+=value;}}};
97+ if(broken==='legacy-schema')processMock.argv.push('', 'solar-state-snapshot.v2');
5398 await new AsyncFunction('puppeteer','process','document','location','getComputedStyle',source)(
5499 {launch:async()=>browser},processMock,document,{pathname:'/sol/releases/fixture/index.html',hash:''},()=>({visibility:'visible'}));
55100 const result=JSON.parse(output);
56101 assert.ok(calls.includes('close'),'browser ownership and cleanup are retained');
57- if(!broken){
102+ if(!broken||broken==='legacy-schema' ){
58103 assert.equal(result.stderr,'');
59104 assert.match(result.observationDom,/data-experience="observe"/);
60105 assert.match(result.observationDom,/Base: loading/,'hidden model placeholder is allowed before native Research entry');
@@ -84,6 +129,20 @@ def test_sun_transport_requires_initial_observe_capture(self):
84129 with self .assertRaisesRegex (AssertionError , "initial Observe capture" ):
85130 browser_smoke .dump_dom ("browser" , "http://127.0.0.1/sol/releases/fixture/index.html" )
86131
132+ def test_declared_legacy_schema_reaches_the_driver_and_python_assertion (self ):
133+ legacy = READY_SUN .replace ('solar-state-snapshot.v3' , 'solar-state-snapshot.v2' )
134+ payload = {"dom" : legacy , "stderr" : "" , "observationDom" :
135+ '<body data-experience="observe"><img id="observationImage"></body>' }
136+ completed = subprocess .CompletedProcess ([], 0 , json .dumps (payload ), "" )
137+ with patch .object (browser_smoke .subprocess , "run" , return_value = completed ) as transport :
138+ self .assertEqual (browser_smoke .dump_dom ("browser" , "http://127.0.0.1/index.html" ,
139+ solar_schema = "solar-state-snapshot.v2" ), (legacy , "" ))
140+ self .assertEqual (transport .call_args .args [0 ][- 2 :], ["" , "solar-state-snapshot.v2" ])
141+ with patch .object (browser_smoke , "dump_dom" , side_effect = [(legacy , "" ), RuntimeError ("next surface" )]) as dump :
142+ with self .assertRaisesRegex (RuntimeError , "next surface" ):
143+ browser_smoke .run_smoke ("http://127.0.0.1" , "browser" , "solar-state-snapshot.v2" )
144+ self .assertEqual (dump .call_args_list [0 ].kwargs , {"solar_schema" : "solar-state-snapshot.v2" })
145+
87146 def test_sun_transport_allows_hidden_model_placeholder_only_in_observe (self ):
88147 payload = {"dom" : READY_SUN , "stderr" : "" , "observationDom" :
89148 '<body data-experience="observe"><img id="observationImage"><div>Base: loading</div><div>Loading snapshot.</div></body>' }
0 commit comments