Files

74 lines
3.4 KiB
JavaScript

'use strict';
const { test } = require('node:test'),
assert = require('node:assert/strict'),
{ createCanvas } = require('@napi-rs/canvas');
const { managementFixture } = require('./management-fixture.cjs');
test(
'composer hides nonvisual capability labels, uses SVG and adapts picture input to selected model',
{ timeout: 90000 },
async (t) => {
require('../fixtures/isolated-vault-key.cjs')(t);
const f = await managementFixture(t, { browser: true }),
{ page, open, store, assistant } = f;
store.saveSettings({
...store.settings(),
runtimePath: process.execPath,
apiKey: 'TEST_IMAGE_UI_KEY',
});
const row = store.providers.read('deepseek'),
dir = store.providers.save({
...row,
models: [{ id: 'plain-model' }, { id: 'vision-model', inputModalities: ['text', 'image'] }],
});
store.providers.chooseDefault({
version: dir.version,
providerId: 'deepseek',
modelId: 'plain-model',
});
let inputs = [];
assistant.runtime.chat = async (input) => {
inputs.push(input);
return JSON.stringify({ reply: '已通过图像内容收到图片。', actions: [] });
};
await open();
const picker = page.getByRole('button', { name: /选择模型/ }),
send = page.getByRole('button', { name: '发送', exact: true });
await picker.waitFor();
assert.doesNotMatch(await picker.innerText(), /能力未知|视觉/);
assert.equal(await page.locator('#assistant-attach svg').count(), 1);
assert.doesNotMatch(await page.locator('#assistant-files').getAttribute('accept'), /\.png/);
const file = {
name: 'picture.png',
mimeType: 'image/png',
buffer: createCanvas(40, 20).toBuffer('image/png'),
};
await page.locator('#assistant-files').setInputFiles(file);
await page.getByText('当前模型不支持图片,请先选择视觉模型。', { exact: true }).waitFor();
assert.equal(inputs.length, 0);
await picker.click();
await page.getByRole('option', { name: 'vision-model', exact: true }).click();
await page.waitForFunction(() =>
document.querySelector('#assistant-files').accept.includes('.png'),
);
await page.locator('#assistant-files').setInputFiles(file);
await page.getByRole('button', { name: '预览附件 picture.png', exact: true }).waitFor();
await page.getByRole('button', { name: '预览附件 picture.png', exact: true }).click();
const dialog = page.getByRole('dialog', { name: '预览附件 picture.png', exact: true });
await dialog.getByRole('img', { name: 'picture.png', exact: true }).waitFor();
await dialog.getByRole('button', { name: '关闭', exact: true }).click();
await picker.click();
await page.getByRole('option', { name: 'plain-model', exact: true }).click();
await page
.getByText('当前模型不支持图片,请选择视觉模型或移除图片。', { exact: true })
.waitFor();
assert.equal(await send.isDisabled(), true);
await picker.click();
await page.getByRole('option', { name: 'vision-model', exact: true }).click();
await page.waitForFunction(() => !document.querySelector('#assistant-send').disabled);
await send.click();
await page.getByText('已通过图像内容收到图片。', { exact: true }).waitFor();
assert.equal(inputs[0].images.length, 1);
await page.waitForFunction(() => document.querySelector('.aw-sent-image')?.naturalWidth > 0);
},
);