Files

101 lines
4.3 KiB
JavaScript

'use strict';
const { test } = require('node:test'),
assert = require('node:assert/strict');
const { managementFixture } = require('./management-fixture.cjs');
test(
'attachments preview/remove locally, send without extra text and show verified visual capability',
{ timeout: 120000 },
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_ATTACHMENT_UI_KEY',
});
const row = store.providers.read('deepseek'),
directory = store.providers.save({
...row,
models: [
{
id: 'vision-fixture',
name: '供应商确认支持图像输入的完整长模型名称',
inputModalities: ['text', 'image'],
},
],
});
store.providers.chooseDefault({
version: directory.version,
providerId: 'deepseek',
modelId: 'vision-fixture',
});
let calls = 0,
inputs = [];
assistant.runtime.chat = async (input) => {
calls++;
inputs.push(input);
return JSON.stringify({ reply: '附件型号 ABC,数量 12。', actions: [] });
};
await open();
await page.getByRole('button', { name: /选择模型.*视觉/ }).waitFor();
await page.setViewportSize({ width: 390, height: 844 });
const label = page.locator('#assistant-model-picker');
assert.match(await label.innerText(), /供应商确认支持图像输入的完整长模型名称/);
await page.waitForFunction(() => {
const e = document.querySelector('#assistant-model-picker');
return e && e.scrollWidth <= e.clientWidth;
});
assert.equal(await label.evaluate((e) => e.scrollWidth <= e.clientWidth), true);
await page.setViewportSize({ width: 1440, height: 1000 });
const send = page.getByRole('button', { name: '发送', exact: true });
assert.equal(await send.isDisabled(), true);
const file = {
name: 'sample.csv',
mimeType: 'text/csv',
buffer: Buffer.from('型号,数量\nABC,12'),
};
await page.locator('#assistant-files').setInputFiles(file);
await page.getByText('已解析', { exact: false }).waitFor();
assert.equal(calls, 0);
await page.waitForFunction(() => !document.querySelector('#assistant-send').disabled);
await page.setViewportSize({ width: 390, height: 844 });
const out = require('node:path').resolve(__dirname, '../../output/verification/dsh-settings');
await require('node:fs/promises').mkdir(out, { recursive: true });
await page.screenshot({
path: require('node:path').join(out, 'attachment-mobile.png'),
fullPage: true,
});
await page.setViewportSize({ width: 1440, height: 1000 });
await page.getByRole('button', { name: '预览附件 sample.csv', exact: true }).click();
await page.getByText('型号,数量\nABC,12', { exact: true }).waitFor();
await page
.getByRole('dialog', { name: '预览附件 sample.csv', exact: true })
.getByRole('button', { name: '关闭', exact: true })
.click();
store.db.prepare('UPDATE assistant_attachments SET expires_at=0').run();
await page.getByRole('button', { name: '移除附件 sample.csv', exact: true }).click();
await page
.getByRole('button', { name: '移除附件 sample.csv', exact: true })
.waitFor({ state: 'hidden' });
assert.equal(await send.isDisabled(), true);
await page.locator('#assistant-files').setInputFiles(file);
await page.getByText('已解析', { exact: false }).waitFor();
assert.equal(await send.isEnabled(), true);
await send.click();
await page.getByText('附件型号 ABC,数量 12。', { exact: true }).waitFor();
assert.equal(calls, 1);
assert.match(inputs[0].context.attachments[0].content, /ABC,12/);
assert.equal(await page.locator('#assistant-attachment-list').innerText(), '');
await page.getByLabel('发送给 DSH', { exact: true }).fill('继续分析');
await send.click();
await page
.locator('.assistant-answer')
.nth(1)
.getByText('附件型号 ABC,数量 12。', { exact: true })
.waitFor();
assert.equal(calls, 2);
assert.match(inputs[1].context.attachments[0].content, /ABC,12/);
},
);