mirror of
https://github.com/steveseguin/caption-local.git
synced 2026-10-10 01:59:31 +00:00
Validate sustained CUDA capture and preserve Windows/WSL environments
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
"""Controlled HTTPS-origin preview; assets intercepted locally, no public publishing."""
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -11,10 +13,13 @@ from browser_support import browser_options
|
||||
from browser_capture_connection import TOKEN, ROOT
|
||||
from service_test_support import require_free_port
|
||||
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--output',type=Path,required=True,help='Keep each preview separate from earlier failure evidence')
|
||||
args=parser.parse_args()
|
||||
require_free_port(8778)
|
||||
child=subprocess.Popen([sys.executable,'scripts/browser_capture_connection.py','--serve-https'],
|
||||
creationflags=getattr(subprocess,'CREATE_NO_WINDOW',0))
|
||||
report={'scope':'Intercepted HTTPS-origin page assets with real loopback HTTP requests and fake inference; not a deployed HTTPS site', 'scenarios':[]}
|
||||
report={'scope':'CDP-intercepted HTTPS-origin page assets with real loopback HTTP requests and fake inference; not a deployed HTTPS site', 'scenarios':[]}
|
||||
try:
|
||||
for _ in range(100):
|
||||
try:
|
||||
@@ -34,24 +39,33 @@ try:
|
||||
console=[]
|
||||
page.on('console',lambda message: console.append(message.text) if message.type=='error' else None)
|
||||
page.on('requestfailed',lambda request: failures.append({'url':request.url,'error':request.failure}))
|
||||
def route(request):
|
||||
url=request.request.url
|
||||
intercepted=[]
|
||||
def route(event):
|
||||
request_id=event['requestId']
|
||||
url=event['request']['url']
|
||||
intercepted.append(urlsplit(url).path)
|
||||
if url.startswith('http://127.0.0.1:8778/'):
|
||||
request.continue_(); return
|
||||
cdp.send('Fetch.continueRequest',{'requestId':request_id}); return
|
||||
if url.startswith('https://caption.ninja/'):
|
||||
relative=urlsplit(url).path.lstrip('/')
|
||||
source=(ROOT/'samples/captionninja'/relative).resolve()
|
||||
base=(ROOT/'samples/captionninja').resolve()
|
||||
if source.is_relative_to(base) and source.is_file():
|
||||
request.fulfill(path=str(source),content_type='text/html' if source.suffix=='.html' else 'application/javascript'); return
|
||||
request.abort()
|
||||
context.route('**/*',route)
|
||||
cdp.send('Fetch.fulfillRequest',{'requestId':request_id,'responseCode':200,
|
||||
'responseHeaders':[{'name':'Content-Type','value':'text/html' if source.suffix=='.html' else 'application/javascript'}],
|
||||
'body':base64.b64encode(source.read_bytes()).decode('ascii')}); return
|
||||
cdp.send('Fetch.failRequest',{'requestId':request_id,'errorReason':'BlockedByClient'})
|
||||
# Probe direct Fetch events without relying on Playwright's usual
|
||||
# page/network event pairing for worklet module loads.
|
||||
cdp.on('Fetch.requestPaused',route)
|
||||
cdp.send('Fetch.enable',{'patterns':[{'urlPattern':'*'}]})
|
||||
context.route_web_socket('**/*',lambda socket:socket.close())
|
||||
page.goto('https://caption.ninja/capture-local.html')
|
||||
page.fill('#endpoint','http://127.0.0.1:8778');page.fill('#connectionToken',TOKEN);page.click('#connect')
|
||||
page.wait_for_function('() => !connection.checking')
|
||||
ready=not page.locator('#start').is_disabled()
|
||||
scenario={'permission':permission,'ready':ready,'request_failures':failures,'console':console}
|
||||
scenario={'permission':permission,'ready':ready,'request_failures':failures,'console':console,
|
||||
'intercepted_paths':intercepted,'secure_context':page.evaluate('isSecureContext')}
|
||||
report['scenarios'].append(scenario)
|
||||
if ready:
|
||||
page.click('#start')
|
||||
@@ -69,6 +83,6 @@ except Exception as exc:
|
||||
report['error']=repr(exc);report['passed']=False
|
||||
finally:
|
||||
child.terminate();child.wait(timeout=15)
|
||||
output=ROOT/'evidence/gpu-validation/https-preview.json';output.parent.mkdir(parents=True,exist_ok=True)
|
||||
output=args.output;output.parent.mkdir(parents=True,exist_ok=True)
|
||||
output.write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8');print(json.dumps(report,indent=2))
|
||||
if not report['passed']: raise SystemExit('HTTPS preview validation incomplete; evidence retained')
|
||||
|
||||
Reference in New Issue
Block a user