'use strict'; const { test } = require('node:test'), assert = require('node:assert/strict'), fs = require('node:fs'), os = require('node:os'), path = require('node:path'), crypto = require('node:crypto'); const { managementFixture } = require('./management-fixture.cjs'), { OperationJournal } = require('../../src/modules/assistant/operation-journal.cjs'); test( 'composer uses an accessible icon and settings save only after risk acknowledgement', { timeout: 180000 }, async (t) => { require('../fixtures/isolated-vault-key.cjs')(t); const f = await managementFixture(t, { browser: true }), { page, open, store, users, assistant } = f, file = path.join(os.tmpdir(), 'dsh-review-' + crypto.randomUUID() + '.sqlite'), journal = new OperationJournal({ file }); assistant.journal = journal; t.after(() => { journal.close(); fs.rmSync(file, { force: true }); }); store.saveSettings({ ...store.settings(), runtimePath: process.execPath, apiKey: 'TEST_REVIEW_UI_KEY', allowActions: true, }); assistant.runtime.chat = async () => JSON.stringify({ reply: '建议调整发送时间,请审查风险。', actions: [ { kind: 'update_configuration', targetId: 'schedule', changes: { times: ['10:00', '18:00'] }, }, ], }); const output = path.resolve(__dirname, '../../output/verification/dsh-settings'); await fs.promises.mkdir(output, { recursive: true }); await open(); const send = page.getByRole('button', { name: '发送', exact: true }), input = page.getByRole('textbox', { name: '发送给 DSH', exact: true }); await input.waitFor(); assert.equal(await send.isDisabled(), true); await input.fill(' '); assert.equal(await send.isDisabled(), true); await input.fill('调整发送计划'); await page.waitForFunction(() => !document.querySelector('#assistant-send').disabled); assert.equal(await send.isEnabled(), true); assert.ok(await send.locator('svg').count()); await send.click(); await page.getByRole('button', { name: '查看操作(1)', exact: true }).click(); await page.getByRole('button', { name: '审查修改', exact: true }).click(); const dialog = page.getByRole('dialog', { name: '审查设置修改', exact: true }); await dialog.waitFor(); assert.match(await dialog.innerText(), /09:00/); assert.match(await dialog.innerText(), /10:00/); assert.match(await dialog.innerText(), /风险/); const authorize = dialog.getByRole('button', { name: '授权并保存', exact: true }); assert.equal(await authorize.isDisabled(), true); await page.screenshot({ path: path.join(output, 'review-desktop.png'), fullPage: true }); const before = users.settings(); await dialog.getByRole('button', { name: '取消', exact: true }).click(); assert.deepEqual(users.settings(), before); await page.getByRole('button', { name: '审查修改', exact: true }).click(); await dialog .getByRole('checkbox', { name: '我已阅读以上差异和风险,授权本次修改', exact: true }) .check(); await authorize.click(); await page.getByText('配置已保存', { exact: true }).waitFor(); assert.deepEqual(users.settings().schedule.times, ['10:00', '18:00']); await page.setViewportSize({ width: 390, height: 844 }); const box = await send.boundingBox(); assert.ok(box.width >= 40 && box.height >= 40); assert.ok(box.x + box.width <= 390); assert.equal( await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, ); await page.screenshot({ path: path.join(output, 'mobile.png'), fullPage: true }); assistant.runtime.chat = ({ signal }) => new Promise((resolve, reject) => signal.addEventListener('abort', () => reject(signal.reason), { once: true }), ); await input.fill('测试停止回复'); await send.click(); const stop = page.getByRole('button', { name: '停止回复', exact: true }); await stop.waitFor(); assert.equal(await stop.locator('svg rect').count(), 1); await stop.click(); await page.getByText('已停止', { exact: true }).waitFor(); assert.equal(await send.isDisabled(), true); await page.setViewportSize({ width: 390, height: 844 }); await page.evaluate(() => { const picker = document.querySelector('#assistant-model-picker'); AssistantModelPicker; picker.textContent = 'DeepSeek / skyworth-deepseek-v4.1-flash-with-complete-long-model-name'; }); const model = page.locator('#assistant-model-picker'); const full = await model.evaluate((e) => ({ clipped: e.scrollWidth > e.clientWidth, whiteSpace: getComputedStyle(e).whiteSpace, text: e.textContent, })); assert.equal(full.clipped, false); assert.notEqual(full.whiteSpace, 'nowrap'); assert.match(full.text, /complete-long-model-name/); assistant.runtime.chat = async () => JSON.stringify({ reply: Array.from( { length: 80 }, (_, i) => '第' + i + '段,供阅读历史消息的滚动测试。', ).join('\n\n'), actions: [], }); await input.fill('生成长回答以验证滚动到底部'); await send.click(); await page .locator('.assistant-turn') .last() .getByRole('button', { name: '复制回答', exact: true }) .waitFor(); await page.locator('#assistant-messages').evaluate((e) => { e.scrollTop = 0; e.dispatchEvent(new Event('scroll')); }); const latest = page.getByRole('button', { name: '滚动到底部', exact: true }); await latest.waitFor(); await latest.click(); assert.equal( await page .locator('#assistant-messages') .evaluate((e) => e.scrollHeight - e.clientHeight - e.scrollTop < 10), true, ); await latest.waitFor({ state: 'hidden' }); }, );