// Execute unmodified upstream logic in an isolated VM; no browser/network calls. const vm=require('node:vm'),fs=require('node:fs'),assert=require('node:assert/strict'); let code=fs.readFileSync(__dirname+'/vendor/openwebui-reasoning-effort.user.js','utf8'); code=code.replace("\tif (document.documentElement) {", "\twindow.testExports = {rememberRegistry, applySelectionToBody, effortInfoForModel, state};\n\tif (document.documentElement) {"); const context=vm.createContext({window:{},document:{documentElement:null,addEventListener(){}},console,localStorage:{getItem(){return null;}},requestAnimationFrame(){},setTimeout(){},URL}); vm.runInContext(code,context); const t=context.window.testExports; const registry=JSON.parse(fs.readFileSync(__dirname+'/registry.json','utf8')); t.rememberRegistry(registry); let count=0; for(const [id,rule] of Object.entries(registry.models)){ const model={id,name:id,owned_by:'openai'};t.state.models.set(id,model); if(!rule.thinking){assert.equal(t.effortInfoForModel(model).show,false);continue;} for(const level of Object.keys(rule.mappings)){ const body={model:id,params:{temperature:0.7,reasoning_effort:'high',custom_params:{chat_template_kwargs:{preserve_thinking:true}}}}; assert.equal(t.applySelectionToBody(body,model,level,false),true); assert.equal(body.params.custom_params.reasoning_effort,level); assert.equal(body.params.custom_params.chat_template_kwargs.enable_thinking,level!=='none'); assert.equal(body.params.custom_params.chat_template_kwargs.preserve_thinking,true); assert.equal(body.params.temperature,0.7); assert.equal(body.params.reasoning_effort,undefined); count++; } } console.log(`${count} upstream selector request mappings passed; non-Qwen controls hidden`);