22 lines
6.8 KiB
JavaScript
22 lines
6.8 KiB
JavaScript
'use strict';
|
|
const {test}=require('node:test'),assert=require('node:assert/strict');const {managementFixture}=require('./management-fixture.cjs');
|
|
test('assistant settings manage providers and default models without exposing a saved key',{timeout:120000},async t=>{
|
|
const {page,open,calls}=await managementFixture(t,{browser:true});await open('#assistant-settings');await page.getByRole('button',{name:'添加供应商',exact:true}).click();await page.getByLabel('供应商类型',{exact:true}).selectOption('openai');await page.getByLabel('供应商名称',{exact:true}).fill('测试供应商');await page.getByLabel('API 根地址',{exact:true}).fill('https://models.example/v1');await page.getByLabel('API 密钥',{exact:true}).fill('TEST_PROVIDER_UI_KEY');await page.getByLabel('模型列表',{exact:true}).fill('test-a|测试模型 A\ntest-b|测试模型 B');await page.getByRole('button',{name:'保存供应商',exact:true}).click();await page.getByText('测试供应商',{exact:true}).waitFor();assert.equal(calls(),0);assert.doesNotMatch(await page.locator('body').innerText(),/TEST_PROVIDER_UI_KEY/);
|
|
await page.getByLabel('默认模型',{exact:true}).selectOption({label:'测试供应商 / 测试模型 A'});await page.getByRole('button',{name:'保存默认模型',exact:true}).click();await page.getByText('默认模型已保存。',{exact:true}).waitFor();await page.getByLabel('启用 DSH 对话诊断',{exact:true}).check();await page.getByRole('button',{name:'保存助手设置',exact:true}).click();await require('node:fs/promises').mkdir('output/verification/dsh-providers',{recursive:true});await page.screenshot({path:'output/verification/dsh-providers/settings-desktop.png',fullPage:true});await page.goto(new URL('/#assistant',page.url()).href);await page.getByRole('button',{name:/选择模型/}).click();await page.getByRole('option',{name:'测试模型 B',exact:true}).click();await page.getByLabel('发送给 DSH',{exact:true}).fill('分析当前状态');await page.getByRole('button',{name:'发送',exact:true}).click();await page.getByText('使用模型 test-b',{exact:true}).waitFor();assert.equal(calls(),1);await page.screenshot({path:'output/verification/dsh-providers/assistant-model-selected.png',fullPage:true});await page.setViewportSize({width:390,height:844});await page.screenshot({path:'output/verification/dsh-providers/assistant-mobile.png',fullPage:true});
|
|
});
|
|
test('the tool return button is prominent on desktop and mobile and returns to the tools section',{timeout:90000},async t=>{
|
|
const {page,open}=await managementFixture(t,{browser:true});await open();for(const width of [1440,390]){await page.setViewportSize({width,height:900});const back=page.getByRole('link',{name:'返回工具',exact:true});await back.waitFor();const box=await back.boundingBox();assert.ok(box.height>=44);assert.ok(box.width>=100);assert.equal(await back.getAttribute('href'),'#tools');}await page.getByRole('link',{name:'返回工具',exact:true}).click();await page.getByRole('navigation',{name:'工具导航'}).waitFor();assert.equal(await page.locator('.assistant-workspace').count(),0);
|
|
});
|
|
test('opening another provider editor never silently discards an unsaved key or name',{timeout:90000},async t=>{
|
|
const {page,open}=await managementFixture(t,{browser:true});await open('#assistant-settings');await page.getByRole('button',{name:'添加供应商',exact:true}).click();await page.getByLabel('供应商名称',{exact:true}).fill('未保存供应商');await page.getByLabel('API 密钥',{exact:true}).fill('UNSAVED_TEST_KEY');await page.getByRole('button',{name:'编辑',exact:true}).first().click();await page.getByRole('dialog',{name:'未保存的修改',exact:true}).waitFor();await page.getByRole('button',{name:'留在此页',exact:true}).click();assert.equal(await page.getByLabel('供应商名称',{exact:true}).inputValue(),'未保存供应商');assert.equal(await page.getByLabel('API 密钥',{exact:true}).inputValue(),'UNSAVED_TEST_KEY');
|
|
});
|
|
test('choosing the first model starts conversation updates and an external trash clears its draft',{timeout:90000},async t=>{
|
|
const f=await managementFixture(t,{browser:true}),{page,open,store}=f;store.saveSettings({...store.settings(),apiKey:'TEST_FIRST_MODEL_KEY'});await open();await page.getByRole('button',{name:/选择模型/}).click();const stream=page.waitForRequest(r=>r.url().includes('/stream?'),{timeout:5000});await page.getByRole('option',{name:'deepseek-flash',exact:true}).click();await stream;await page.getByRole('button',{name:'归档会话',exact:true}).waitFor();const input=page.getByLabel('发送给 DSH',{exact:true});await input.fill('UNSENT_DRAFT');const owner=f.users.users().find(u=>u.username==='admin').id,c=store.listConversations(owner).items[0];store.trash(c.id,owner,{version:store.conversation(c.id,owner).version});await page.waitForFunction(()=>document.querySelector('#assistant-input')?.value==='');assert.equal(await page.locator('[data-assistant-conversation]').count(),0);
|
|
});
|
|
test('provider save locks mutable fields until its acknowledged response completes',{timeout:90000},async t=>{
|
|
const {page,open,store}=await managementFixture(t,{browser:true});await open('#assistant-settings');await page.getByRole('button',{name:'添加供应商',exact:true}).click();await page.getByLabel('供应商名称',{exact:true}).fill('NAME_SUBMITTED');await page.getByLabel('API 密钥',{exact:true}).fill('TEST_PENDING_PROVIDER_KEY');let release;const gate=new Promise(r=>release=r);t.after(()=>release());await page.route('**/api/assistant/providers',async route=>{if(route.request().method()==='POST'){await gate;await route.continue();}else await route.continue();});const started=page.waitForRequest(r=>r.url().endsWith('/providers')&&r.method()==='POST');await page.getByRole('button',{name:'保存供应商',exact:true}).click();await started;assert.equal(await page.getByLabel('供应商名称',{exact:true}).isDisabled(),true);assert.equal(await page.getByLabel('API 密钥',{exact:true}).isDisabled(),true);release();await page.getByText('NAME_SUBMITTED',{exact:true}).waitFor();assert.ok(store.providers.list().providers.some(p=>p.name==='NAME_SUBMITTED'));
|
|
});
|
|
test('provider cancel asks once before discarding a dirty draft',{timeout:90000},async t=>{
|
|
const {page,open}=await managementFixture(t,{browser:true});await open('#assistant-settings');await page.getByRole('button',{name:'添加供应商',exact:true}).click();await page.getByLabel('供应商名称',{exact:true}).fill('UNSAVED_NAME');await page.getByRole('button',{name:'取消',exact:true}).click();await page.getByRole('dialog',{name:'未保存的修改',exact:true}).waitFor();await page.getByRole('button',{name:'放弃并继续',exact:true}).click();await page.locator('#provider-edit-form').waitFor({state:'hidden'});assert.equal(await page.getByRole('dialog',{name:'未保存的修改',exact:true}).count(),0);
|
|
});
|