Core regression / Python core, intervention UI and release configuration (push) Successful in 16m20s
Core regression / JavaScript syntax (push) Successful in 11s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 11m11s
Core regression / JavaScript syntax (pull_request) Successful in 7s
71 lines
4.6 KiB
JavaScript
71 lines
4.6 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 rendered=`e.getBoundingClientRect().width>0&&!e.closest('details:not([open])')`;
|
|
const visible=selector=>`[...document.querySelectorAll(${JSON.stringify(selector)})].find(e=>${rendered})`;
|
|
const button=text=>`[...document.querySelectorAll('button')].find(e=>${rendered}&&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('自定义设置')&&e.closest('details').querySelector('input[aria-label="API 地址"]')?.value===${JSON.stringify(endpoint)})`);
|
|
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));
|
|
}
|
|
}
|