Files
dxdesigner-part-replacement/tools/verify_dsh_model_settings.mjs
阿白叔 374e1cd5bf
Core regression / Python core and release configuration (push) Successful in 15s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
fix(dsh): preserve acrylic and restore durable native model settings
2026-11-03 11:41:50 +08:00

70 lines
4.4 KiB
JavaScript

/** Real settings form, provider discovery and persistence against an owned fixture. */
import assert from 'node:assert/strict';
import {createServer} from 'node:http';
import path from 'node:path';
export async function verifyModelSettings(c, output) {
const requests=[];
const server=createServer((req,res)=>{
requests.push({method:req.method,path:req.url});
res.writeHead(req.url==='/v1/models'?200:404,{'Content-Type':'application/json'});
res.end(JSON.stringify({object:'list',data:[{id:'issue16-fixture-model',object:'model',owned_by:'acceptance'}]}));
});
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
const endpoint=`http://127.0.0.1:${server.address().port}/v1`;
const visible=selector=>`[...document.querySelectorAll(${JSON.stringify(selector)})].find(e=>e.getBoundingClientRect().width>0)`;
const button=text=>`[...document.querySelectorAll('button')].find(e=>e.getBoundingClientRect().width>0&&e.textContent.trim()===${JSON.stringify(text)})`;
async function wait(expression){
const end=Date.now()+20000;
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}
throw Error('Models acceptance timed out: '+expression);
}
async function type(selector,text){
await c.click(visible(selector));
await c.call('Input.insertText',{text});
await wait(`(${visible(selector)})?.value===${JSON.stringify(text)}`);
}
try{
// The caller has reached the actual upstream Custom model API form.
await type('input[aria-label="Provider ID"]','issue16-fixture');
await type('input[aria-label="API 地址"]',endpoint);
const protocol='select[aria-label="API 协议"]';
// This is a native keyboard selection, not a direct settings RPC.
const choices=await c.evaluate(`[...(${visible(protocol)}).options].map(x=>x.value)`);
const target=choices.indexOf('openai-completions');
assert.ok(target>=0);
await c.click(visible(protocol));
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Home',code:'Home',windowsVirtualKeyCode:36});
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Home',code:'Home',windowsVirtualKeyCode:36});
for(let i=0;i<target;i++){
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'ArrowDown',code:'ArrowDown',windowsVirtualKeyCode:40});
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'ArrowDown',code:'ArrowDown',windowsVirtualKeyCode:40});
}
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Enter',code:'Enter',windowsVirtualKeyCode:13});
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Enter',code:'Enter',windowsVirtualKeyCode:13});
await wait(`(${visible(protocol)}).value==='openai-completions'`);
await c.click(button('获取可用模型'));
await wait(`document.body.innerText.includes('issue16-fixture-model')`);
assert.deepEqual(requests,[{method:'GET',path:'/v1/models'}]);
const candidate=`[...document.querySelectorAll('[role="dialog"] label')].find(e=>e.textContent.includes('issue16-fixture-model'))?.querySelector('input[type="checkbox"]')`;
if(!await c.evaluate(`(${candidate})?.checked`))await c.click(candidate);
assert.equal(await c.evaluate(`(${candidate})?.checked`),true);
await c.click(button('添加所选'));
await wait(`!![...document.querySelectorAll('input')].find(x=>x.value==='issue16-fixture-model')`);
await c.screenshot(path.join(output,'custom-model-discovery.png'));
await c.click(button('创建提供商'));
await wait(`!document.querySelector('input[aria-label="Provider ID"]')`);
await wait(`document.body.innerText.includes('issue16-fixture')`);
// Reopen the real editor to read committed fields, not the submitted draft.
await c.click(`[...document.querySelectorAll('li')].find(e=>e.textContent.includes('issue16-fixture'))?.querySelector('button')`);
await wait(`document.body.innerText.includes('自定义设置')`);
await c.click(`[...document.querySelectorAll('summary')].find(e=>e.textContent.includes('自定义设置'))`);
await wait(`!![...document.querySelectorAll('input')].find(x=>x.value==='issue16-fixture-model')`);
await c.screenshot(path.join(output,'custom-model-persisted.png'));
return {status:'passed',provider:'issue16-fixture',model:'issue16-fixture-model',requests,
credentialsUsed:false,remoteModelCalls:false};
}finally{
server.closeAllConnections();await new Promise(resolve=>server.close(resolve));
}
}