import json,sys,platform import subprocess,json # Execute the actual WHATWG URL implementation in the installed Node runtime. base='https://example.test/docs/guide/' refs=['image.png','../download/file.csv','/contact','?lang=ja','#downloads','//cdn.example.test/a.png'] js='const base='+json.dumps(base)+'; const refs='+json.dumps(refs)+'; console.log(JSON.stringify(refs.map(ref=>({ref,url:new URL(ref,base).href}))));' rows=json.loads(subprocess.check_output(['node','-e',js],text=True)) slash=json.loads(subprocess.check_output(['node','-e','console.log(JSON.stringify([new URL("image.png","https://example.test/docs/guide").href,new URL("image.png","https://example.test/docs/guide/").href]))'],text=True)) base_element='https://static.example.test/assets/' result={'base':base,'rows':rows,'trailingSlash':slash,'baseElementExample':{'documentBase':base_element,'resolved':json.loads(subprocess.check_output(['node','-e','console.log(JSON.stringify(new URL("image.png","https://static.example.test/assets/").href))'],text=True))},'networkRequests':0} assert rows[1]['url']=='https://example.test/docs/download/file.csv' assert slash==['https://example.test/docs/image.png','https://example.test/docs/guide/image.png'] result['nodeRuntime']=subprocess.check_output(['node','--version'],text=True).strip() from datetime import datetime as _runtime_datetime, timezone as _runtime_timezone result.update({'fixtureCreatedOn':'2026-10-15','executedAt':_runtime_datetime.now(_runtime_timezone.utc).isoformat(),'runtime':platform.python_version(),'synthetic':True}) print(json.dumps(result,ensure_ascii=False,indent=2))