130 lines
6.5 KiB
JavaScript
130 lines
6.5 KiB
JavaScript
'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'),
|
|
{ NativeSchedules } = require('../../src/modules/assistant/native-schedules.cjs'),
|
|
{ OperationJournal } = require('../../src/modules/assistant/operation-journal.cjs');
|
|
test(
|
|
'schedule panel creates edits deletes native tasks and shows a due model reply',
|
|
{ timeout: 90000 },
|
|
async (t) => {
|
|
require('../fixtures/isolated-vault-key.cjs')(t);
|
|
const f = await managementFixture(t, { browser: true }),
|
|
{ page, open, store, assistant } = f,
|
|
file = path.join(os.tmpdir(), 'schedule-ui-' + crypto.randomUUID() + '.sqlite');
|
|
assistant.journal = new OperationJournal({ file });
|
|
t.after(() => {
|
|
assistant.journal.close();
|
|
fs.rmSync(file, { force: true });
|
|
});
|
|
store.saveSettings({
|
|
...store.settings(),
|
|
runtimePath: process.execPath,
|
|
apiKey: 'TEST_SCHEDULE_UI_KEY',
|
|
});
|
|
await NativeSchedules.create({ assistant });
|
|
let calls = 0;
|
|
assistant.runtime.chat = async () => {
|
|
calls++;
|
|
return JSON.stringify({ reply: '原生定时提醒的模型回复。', actions: [] });
|
|
};
|
|
await open();
|
|
await page.getByRole('tab', { name: '任务', exact: true }).click();
|
|
await page.getByRole('button', { name: '新建定时任务', exact: true }).click();
|
|
let dialog = page.getByRole('dialog', { name: '新建定时任务', exact: true });
|
|
await dialog.getByLabel('任务名称', { exact: true }).fill('可编辑提醒');
|
|
await dialog.getByLabel('任务内容', { exact: true }).fill('提醒我检查状态');
|
|
await dialog.getByLabel('延时(秒)', { exact: true }).fill('3600');
|
|
assert.equal(
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).isDisabled(),
|
|
true,
|
|
);
|
|
await dialog
|
|
.getByRole('checkbox', {
|
|
name: '我确认按此规则定时调用模型,其他操作仍需另行授权',
|
|
exact: true,
|
|
})
|
|
.check();
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).click();
|
|
await page.getByText('可编辑提醒', { exact: true }).waitFor();
|
|
assert.equal(calls, 0);
|
|
await page.getByRole('button', { name: '编辑任务 可编辑提醒', exact: true }).click();
|
|
dialog = page.getByRole('dialog', { name: '编辑定时任务', exact: true });
|
|
await dialog.getByLabel('任务名称', { exact: true }).fill('修改后的提醒');
|
|
await dialog
|
|
.getByRole('checkbox', {
|
|
name: '我确认按此规则定时调用模型,其他操作仍需另行授权',
|
|
exact: true,
|
|
})
|
|
.check();
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).click();
|
|
await page.getByText('修改后的提醒', { exact: true }).waitFor();
|
|
await page.getByRole('button', { name: '删除任务 修改后的提醒', exact: true }).click();
|
|
await page
|
|
.getByRole('dialog', { name: '删除定时任务', exact: true })
|
|
.getByRole('button', { name: '确认删除任务', exact: true })
|
|
.click();
|
|
await page.getByText('修改后的提醒', { exact: true }).waitFor({ state: 'hidden' });
|
|
const record = assistant.record.bind(assistant);
|
|
assistant.record = (id, principal, step, status, detail) => {
|
|
if (step === 'schedule_create' && status === 'success')
|
|
throw Error('audit failure after native commit');
|
|
return record(id, principal, step, status, detail);
|
|
};
|
|
await page.getByRole('button', { name: '新建定时任务', exact: true }).click();
|
|
dialog = page.getByRole('dialog', { name: '新建定时任务', exact: true });
|
|
await dialog.getByLabel('任务名称', { exact: true }).fill('未知提交核实');
|
|
await dialog.getByLabel('任务内容', { exact: true }).fill('检查状态');
|
|
await dialog.getByRole('checkbox').check();
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).click();
|
|
await dialog
|
|
.getByRole('alert')
|
|
.getByText(/勿重复提交/)
|
|
.waitFor();
|
|
await dialog.getByRole('checkbox').uncheck();
|
|
await dialog.getByRole('checkbox').check();
|
|
assert.equal(
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).isDisabled(),
|
|
true,
|
|
);
|
|
assistant.record = record;
|
|
await dialog.getByRole('button', { name: '取消', exact: true }).click();
|
|
await page.getByRole('button', { name: '刷新任务', exact: true }).click();
|
|
await page.getByText('未知提交核实', { exact: true }).waitFor();
|
|
assert.equal(store.db.prepare('SELECT COUNT(*) n FROM assistant_schedule_tasks').get().n, 1);
|
|
await page.getByRole('button', { name: '删除任务 未知提交核实', exact: true }).click();
|
|
await page.getByRole('button', { name: '确认删除任务', exact: true }).click();
|
|
await page.getByText('未知提交核实', { exact: true }).waitFor({ state: 'hidden' });
|
|
await page.getByRole('button', { name: '新建定时任务', exact: true }).click();
|
|
dialog = page.getByRole('dialog', { name: '新建定时任务', exact: true });
|
|
await dialog.getByLabel('任务名称', { exact: true }).fill('短延时提醒');
|
|
await dialog.getByLabel('任务内容', { exact: true }).fill('提醒我检查状态');
|
|
await dialog.getByLabel('延时(秒)', { exact: true }).fill('1');
|
|
await dialog
|
|
.getByRole('checkbox', {
|
|
name: '我确认按此规则定时调用模型,其他操作仍需另行授权',
|
|
exact: true,
|
|
})
|
|
.check();
|
|
await dialog.getByRole('button', { name: '确认保存', exact: true }).click();
|
|
await page.getByText('原生定时提醒的模型回复。', { exact: true }).waitFor();
|
|
await page.locator('[data-schedule-history]').getByText('已回复', { exact: true }).waitFor();
|
|
assert.equal(calls, 1);
|
|
const output = path.resolve(__dirname, '../../output/verification/dsh-schedules');
|
|
await fs.promises.mkdir(output, { recursive: true });
|
|
await page.screenshot({ path: path.join(output, 'desktop.png'), fullPage: true });
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await page.getByRole('button', { name: '右侧栏', exact: true }).click();
|
|
await page.getByRole('tab', { name: '任务', exact: true }).click();
|
|
assert.equal(
|
|
await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth),
|
|
true,
|
|
);
|
|
await page.screenshot({ path: path.join(output, 'mobile.png'), fullPage: true });
|
|
},
|
|
);
|