smodusermc/offline-games / _tools /test_thirty_dollar_audio.py
smodusermc's picture
download
raw
5.51 kB
"""Decode every catalog sound and exercise real preview/sequence UI with outside network blocked."""
import os,sys,json,shutil,threading,importlib.util,hashlib
from pathlib import Path
from playwright.sync_api import sync_playwright
HERE=Path('/home/user/game-archive');R=HERE/'reports'
sys.argv=[sys.argv[0]]
spec=importlib.util.spec_from_file_location('archive_verifier',HERE/'tools/verify_games.py');v=importlib.util.module_from_spec(spec);spec.loader.exec_module(v)
m=json.loads((R/'game-6.json').read_text());stage=v.STAGE;shutil.rmtree(stage,ignore_errors=True);stage.mkdir()
server=None
result={'game_id':6,'name':'Thirty Dollar Website','scope':'Network-blocked local HTTP mirror. Every catalog audio file decoded; sampled UI playback checked. Not every editor feature tested.'}
try:
files={f['path']:f for f in m['files']};v.api.download_bucket_files(v.BUCKET,[(key,stage/key) for key in files],raise_on_missing_files=True)
state=v.State(m);state.repair=False
server=v.ThreadingHTTPServer(('127.0.0.1',0),v.Handler);server.daemon_threads=False;server.state=state;threading.Thread(target=server.serve_forever,daemon=True).start()
with sync_playwright() as p:
b=p.chromium.launch(headless=True,args=['--no-sandbox','--disable-dev-shm-usage']);ctx=b.new_context(viewport={'width':1280,'height':900},service_workers='block');blocked=[];errors=[]
def gate(route):
if route.request.url.startswith(f'http://127.0.0.1:{server.server_port}/'):route.continue_()
else:blocked.append(route.request.url);route.abort()
ctx.route('**/*',gate);page=ctx.new_page();page.on('pageerror',lambda e:errors.append(str(e)));page.set_default_timeout(20000)
page.goto(f'http://127.0.0.1:{server.server_port}/games/30dolar/index.html',wait_until='domcontentloaded');page.wait_for_function('typeof soundList!=="undefined" && soundList.length===192')
result['decoded_sounds']=page.evaluate('''async()=>{const out=[];for(const item of soundList){if(item.id==='_pause')continue;const url='sounds/'+item.id+'.wav';try{const r=await fetch(url);if(!r.ok)throw Error('HTTP '+r.status);const buffer=await soundcloud.decodeAudioData(await r.arrayBuffer());const channel=buffer.getChannelData(0);let peak=0;for(let i=0;i<channel.length;i+=Math.max(1,Math.floor(channel.length/4096)))peak=Math.max(peak,Math.abs(channel[i]));out.push({id:item.id,url,decoded:true,duration:buffer.duration,channels:buffer.numberOfChannels,frames:buffer.length,sampled_peak:peak});}catch(e){out.push({id:item.id,url,decoded:false,error:String(e)});}}return out;}''')
page.evaluate('''()=>{window.__audioStarts=[];window.__meters=[];const native=AudioBufferSourceNode.prototype.start;AudioBufferSourceNode.prototype.start=function(...args){__audioStarts.push({frames:this.buffer?.length||0,duration:this.buffer?.duration||0,at:args[0]||0});const analyser=soundcloud.createAnalyser();analyser.fftSize=256;const silent=soundcloud.createGain();silent.gain.value=0;this.connect(analyser);analyser.connect(silent);silent.connect(soundcloud.destination);__meters.push(analyser);return native.apply(this,args);};}''')
page.locator('#icons .sound[str="boom"]').click(button='right');page.evaluate('soundcloud.resume()')
rms=[]
for _ in range(15):
page.wait_for_timeout(50);rms.append(page.evaluate('''()=>Math.max(0,...__meters.map(m=>{const a=new Float32Array(m.fftSize);m.getFloatTimeDomainData(a);return Math.sqrt(a.reduce((n,x)=>n+x*x,0)/a.length)}))'''))
result['preview']={'action':'Right-click Vine Boom','source_starts':page.evaluate('__audioStarts.length'),'peak_measured_rms':max(rms),'audio_context_state':page.evaluate('soundcloud.state')}
page.evaluate('cancel({stopSounds:true});window.__audioStarts=[];window.__meters=[];')
for name in ['boom','bruh','bong']:page.locator(f'#icons .sound[str="{name}"]').click()
result['sequence_selected']=page.evaluate('getSequenceData().map(x=>x.sound)')
page.locator('#playBtn').click(button='right');rms=[]
for _ in range(40):
page.wait_for_timeout(50);rms.append(page.evaluate('''()=>Math.max(0,...__meters.map(m=>{const a=new Float32Array(m.fftSize);m.getFloatTimeDomainData(a);return Math.sqrt(a.reduce((n,x)=>n+x*x,0)/a.length)}))'''))
result['sequence_playback']={'action':'Add Vine Boom, Bruh, Bong, then right-click Play to skip the intro','source_starts':page.evaluate('__audioStarts'),'peak_measured_rms':max(rms),'context_state':page.evaluate('soundcloud.state')}
result['decoded_count']=sum(x['decoded'] for x in result['decoded_sounds']);result['decode_failures']=[x for x in result['decoded_sounds'] if not x['decoded']]
result['assertions']={'all_191_catalog_sounds_decode':result['decoded_count']==191,'preview_generates_nonzero_audio':result['preview']['source_starts']>=1 and result['preview']['peak_measured_rms']>0,'three_sound_sequence_generates_nonzero_audio':len(result['sequence_playback']['source_starts'])>=3 and result['sequence_playback']['peak_measured_rms']>0}
result['page_errors']=errors;result['blocked_external_requests']=sorted(set(blocked));result['missing_local_requests']=dict(state.failed)
b.close()
report=R/'thirty-dollar-audio-browser-test.json';report.write_text(json.dumps(result,indent=2));v.api.batch_bucket_files(v.BUCKET,add=[(report,'_verification/thirty-dollar-audio-browser-test.json')])
print('ASSERTIONS',result['assertions']);print('MISSING LOCAL',result['missing_local_requests']);print('ERRORS',errors)
finally:
if server:server.shutdown();server.server_close()
shutil.rmtree(stage,ignore_errors=True)

Xet Storage Details

Size:
5.51 kB
·
Xet hash:
0b46511d3456282b0af0f907ecf393f29d1d056e0c75e2141753b3df8a64dccc

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.