"""Compare article-style downloads with an isolated curl config on own loopback fixtures. Synthetic file bodies only; no npm, EVM, production requests or system config changes. """ import argparse,hashlib,json,os,platform,subprocess,tempfile,threading from pathlib import Path from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer from datetime import datetime,timezone FILES={'package.json':b'{"name":"owned-fixture","private":true}\n','package-lock.json':b'{"name":"owned-fixture","lockfileVersion":3}\n','reproduce-proxy-identity.mjs':b'console.log("owned synthetic fixture");\n','proxy-results.txt':b'{"fixture":true,"not_an_EVM_result":true}\n'} def run(): requests=[] class Handler(BaseHTTPRequestHandler): def answer(self,send_body): requests.append({'method':self.command,'path':self.path});body=FILES.get(self.path.lstrip('/'));self.send_response(200 if body is not None else 404);body=body if body is not None else b'not found';self.send_header('Content-Type','text/plain');self.send_header('Content-Length',str(len(body)));self.end_headers() if send_body:self.wfile.write(body) def do_GET(self):self.answer(True) def do_HEAD(self):self.answer(False) def log_message(self,*args):pass server=ThreadingHTTPServer(('127.0.0.1',0),Handler);worker=threading.Thread(target=server.serve_forever,kwargs={'poll_interval':.05},daemon=True);worker.start();rows=[] try: with tempfile.TemporaryDirectory(prefix='owned-curl-fixture-')as td: root=Path(td);cfg=root/'curl-config';cfg.mkdir();env=os.environ.copy() for k in list(env): if k.lower().endswith('_proxy'):env.pop(k,None) env['CURL_HOME']=str(cfg);env['NO_PROXY']='127.0.0.1';env['no_proxy']='127.0.0.1' for condition,config,fixed in [('clean_before','',False),('head_config_before','head\n',False),('head_config_after','head\n',True)]: (cfg/'.curlrc').write_text(config);out=root/condition;out.mkdir() for name,expected in FILES.items(): target=out/name;url='http://127.0.0.1:'+str(server.server_port)+'/'+name;cmd=['curl']+(['-q','--connect-timeout','5','--max-time','30']if fixed else[])+['-fSLo',str(target),url];start=len(requests);r=subprocess.run(cmd,env=env,capture_output=True,timeout=8);actual=target.read_bytes()if target.exists()else b'' row={'condition':condition,'file':name,'exit_code':r.returncode,'requests':requests[start:],'bytes_saved':len(actual),'matches_fixture_body':actual==expected,'saved_sha256':hashlib.sha256(actual).hexdigest(),'expected_sha256':hashlib.sha256(expected).hexdigest()};rows.append(row) if r.returncode!=0:raise RuntimeError('Fixture curl request failed') if (actual==expected)!=(condition!='head_config_before'):raise RuntimeError('Unexpected fixture body comparison') if row['requests'][0]['method']!=('HEAD'if condition=='head_config_before'else'GET'):raise RuntimeError('Unexpected request method') r=subprocess.run(['curl','-q','--connect-timeout','5','--max-time','30','-fSLo',str(root/'missing.txt'),'http://127.0.0.1:'+str(server.server_port)+'/missing'],env=env,capture_output=True,timeout=8) if r.returncode!=22:raise RuntimeError('Expected curl HTTP failure22') finally:server.shutdown();server.server_close();worker.join(2) if worker.is_alive():raise RuntimeError('Owned server did not stop') return {'observed_at_utc':datetime.now(timezone.utc).isoformat(),'environment':{'python':platform.python_version(),'curl':subprocess.check_output(['curl','--version'],text=True).splitlines()[0]},'fixture_note':'Four synthetic bodies named like the article downloads; not published packages, contract code or EVM evidence.','rows':rows,'corrected_missing_http_exit':r.returncode,'own_server_stopped':True,'limits':'Only default curl head config versus -q first-option behavior. Parent/system config unchanged. Proxy env removed in own child fixture only; -q does not remove environment proxies. No timeout-speed benchmark, npm install, EVM execution, RPC, wallets, Google or AdSense result.'} if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--output',type=Path,required=True);a=p.parse_args() if a.output.exists():raise SystemExit('Choose a new output; existing evidence is preserved') result=run() with a.output.open('x',encoding='utf-8')as f:json.dump(result,f,ensure_ascii=False,indent=2);f.write('\n') print('PASS:12 own-loopback downloads; config-induced HEAD4 differ; corrected GET4 match; HTTP404 refused; owned server stopped')