Simplify Agent settings and start conversations directly
This commit is contained in:
1 parent
f7b1003c4c
commit
0a43ae901f
9 files changed
+402
-102
No files matched your search
@@ -425,6 +425,7 @@ it('requires an explicit advanced model choice before starting use but permits a
|
||||
api.call.mockImplementation(async (operation, input) => {
|
||||
if (operation === 'catalog') return { models: [{ id: 'model-a', name: '模型甲' }], resources: {}, pricing: null };
|
||||
if (operation === 'access') return { published_version: null, enabled: true, versions: [], grants: [], applications: [] };
|
||||
if (operation === 'publish') return { version: 1, draft_revision: input.expected_revision };
|
||||
return base(operation, input);
|
||||
});
|
||||
api.save.mockImplementation(async (_slug, input) => (current = { ...current, ...input, draft_revision: current.draft_revision + 1 }));
|
||||
@@ -450,11 +451,13 @@ it('requires an explicit advanced model choice before starting use but permits a
|
||||
fireEvent.click(screen.getByRole('button', { name: '保存草稿' }));
|
||||
await screen.findByRole('button', { name: '已保存' });
|
||||
fireEvent.click(screen.getByRole('button', { name: '开始使用', exact: true }));
|
||||
expect(await screen.findByRole('button', { name: '确认开始使用' })).toBeEnabled();
|
||||
expect(api.call.mock.calls.some(([operation]) => ['publish', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
expect(await screen.findByRole('region', { name: '智能体对话' })).toBeVisible();
|
||||
expect(screen.queryByRole('button', { name: '确认开始使用' })).not.toBeInTheDocument();
|
||||
expect(api.call.mock.calls.filter(([operation]) => operation === 'publish')).toHaveLength(1);
|
||||
expect(api.call.mock.calls.some(([operation]) => ['preview', 'submit'].includes(operation))).toBe(false);
|
||||
});
|
||||
|
||||
it('shows all advanced settings together and preserves unfinished selections, search and limits when switching pages', async () => {
|
||||
it('shows only model and capability settings together and preserves unfinished selections and search when switching pages', async () => {
|
||||
const base = api.call.getMockImplementation()!;
|
||||
api.call.mockImplementation(async (operation, input) => {
|
||||
if (operation === 'catalog') return {
|
||||
@@ -479,11 +482,13 @@ it('shows all advanced settings together and preserves unfinished selections, se
|
||||
expect(toolbox).toBeVisible();
|
||||
expect(handbook).toBeVisible();
|
||||
expect(model.compareDocumentPosition(toolbox) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(screen.getByText('选它做事时能用的工具。', { exact: true })).toBeVisible();
|
||||
expect(screen.getByText('给它一本手册,照着方法做。', { exact: true })).toBeVisible();
|
||||
expect(screen.queryByText('选它做事时能用的工具。', { exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('给它一本手册,照着方法做。', { exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('group', { name: /^知识库/ })).toBeVisible();
|
||||
expect(screen.getByRole('heading', { name: '费用上限', exact: true })).toBeVisible();
|
||||
expect(screen.getByRole('heading', { name: '运行限制', exact: true })).toBeVisible();
|
||||
expect(screen.queryByText('管理我的云端能力', { exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: '费用上限', exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('heading', { name: '运行限制', exact: true })).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText('工具审批')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('navigation', { name: '配置分类' })).not.toBeInTheDocument();
|
||||
expect(screen.getAllByRole('tab').map(tab => tab.textContent)).toEqual(['介绍与提示词', '高级设置']);
|
||||
|
||||
@@ -494,18 +499,12 @@ it('shows all advanced settings together and preserves unfinished selections, se
|
||||
const search = screen.getByLabelText('搜索工具箱');
|
||||
fireEvent.change(search, { target: { value: '文章' } });
|
||||
fireEvent.click(screen.getByRole('checkbox', { name: '文章整理工具', exact: true }));
|
||||
const steps = screen.getByLabelText('最多执行步数');
|
||||
fireEvent.change(steps, { target: { value: '70' } });
|
||||
const budget = screen.getByLabelText('每次任务上限(词元点数)');
|
||||
await waitFor(() => expect(budget).toBeEnabled());
|
||||
fireEvent.change(budget, { target: { value: '2.50' } });
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: '介绍与提示词' }), { button: 0, ctrlKey: false });
|
||||
const prompt = ' 保留我的原始写作要求。\n一次讨论一个想法。\n';
|
||||
fireEvent.change(screen.getByLabelText('提示词'), { target: { value: prompt } });
|
||||
expect(model).not.toBeVisible();
|
||||
expect(search).not.toBeVisible();
|
||||
expect(budget).not.toBeVisible();
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: '高级设置' }), { button: 0, ctrlKey: false });
|
||||
|
||||
expect(screen.getByLabelText('模型')).toBe(model);
|
||||
@@ -514,15 +513,12 @@ it('shows all advanced settings together and preserves unfinished selections, se
|
||||
expect(search).toHaveValue('文章');
|
||||
expect(screen.getByRole('checkbox', { name: '文章整理工具', exact: true })).toBeChecked();
|
||||
expect(screen.getByRole('checkbox', { name: '写作方法', exact: true })).toBeChecked();
|
||||
expect(steps).toHaveValue(70);
|
||||
expect(budget).toHaveValue(2.5);
|
||||
expect(screen.getByRole('button', { name: '保存费用上限', exact: true })).toBeEnabled();
|
||||
expect(screen.getByLabelText('提示词')).toHaveValue(prompt);
|
||||
const unload = new Event('beforeunload', { cancelable: true });
|
||||
window.dispatchEvent(unload);
|
||||
expect(unload.defaultPrevented).toBe(true);
|
||||
expect(api.save).not.toHaveBeenCalled();
|
||||
expect(api.call.mock.calls.some(([operation]) => ['saveBudget', 'publish', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
expect(api.call.mock.calls.some(([operation]) => ['budget', 'saveBudget', 'resources', 'publish', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
});
|
||||
|
||||
it('retains requirements when model loading fails and offers a usable retry', async () => {
|
||||
@@ -719,7 +715,7 @@ it('saves an existing configured draft without creating or loading a configurati
|
||||
expect(api.call.mock.calls.some(([operation]) => ['threads', 'history', 'preview', 'submit', 'publish'].includes(operation))).toBe(false);
|
||||
});
|
||||
|
||||
it('switches editor pages while retaining unfinished knowledge and budget form inputs', async () => {
|
||||
it('switches editor pages while retaining unfinished knowledge form inputs', async () => {
|
||||
api.list.mockResolvedValue({ agents: [{ ...draft, configuration: { ...EMPTY_CLOUD_CONFIGURATION, model: 'test-model' } }], next_cursor: null });
|
||||
open();
|
||||
fireEvent.click(await screen.findByRole('button', { name: '继续制作', exact: true }));
|
||||
@@ -744,22 +740,16 @@ it('switches editor pages while retaining unfinished knowledge and budget form i
|
||||
fireEvent.click(screen.getByRole('button', { name: '新建知识库' }));
|
||||
const knowledgeName = screen.getByLabelText('知识库名称');
|
||||
fireEvent.change(knowledgeName, { target: { value: '还没创建的资料' } });
|
||||
const budgetInput = screen.getByLabelText('每日上限(词元点数)');
|
||||
await waitFor(() => expect(budgetInput).toBeEnabled());
|
||||
fireEvent.change(budgetInput, { target: { value: '12.50' } });
|
||||
fireEvent.mouseDown(advanced, { button: 0, ctrlKey: false });
|
||||
expect(knowledgeName).toBeVisible();
|
||||
expect(budgetInput).toBeVisible();
|
||||
|
||||
fireEvent.mouseDown(requirements, { button: 0, ctrlKey: false });
|
||||
expect(screen.queryByRole('navigation', { name: '配置分类' })).not.toBeInTheDocument();
|
||||
expect(budgetInput).not.toBeVisible();
|
||||
expect(knowledgeName).not.toBeVisible();
|
||||
expect(screen.getByLabelText('提示词')).toBe(instructions);
|
||||
expect(instructions).toHaveValue('没有保存的要求');
|
||||
fireEvent.mouseDown(advanced, { button: 0, ctrlKey: false });
|
||||
expect(screen.queryByRole('navigation', { name: '配置分类' })).not.toBeInTheDocument();
|
||||
expect(screen.getByLabelText('每日上限(词元点数)')).toBe(budgetInput);
|
||||
expect(budgetInput).toHaveValue(12.5);
|
||||
expect(screen.getByLabelText('知识库名称')).toBe(knowledgeName);
|
||||
expect(knowledgeName).toHaveValue('还没创建的资料');
|
||||
expect(screen.queryByLabelText('消息')).not.toBeInTheDocument();
|
||||
@@ -767,27 +757,39 @@ it('switches editor pages while retaining unfinished knowledge and budget form i
|
||||
expect(api.call.mock.calls.some(([operation]) => ['saveBudget', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
});
|
||||
|
||||
it('retains unsaved instructions while saving a budget independently of the draft', async () => {
|
||||
const configured = { ...draft, configuration: { ...EMPTY_CLOUD_CONFIGURATION, model: 'test-model' } };
|
||||
it('preserves hidden runtime policies while saving model, prompt and capability changes without touching the budget', async () => {
|
||||
const configuration = { ...EMPTY_CLOUD_CONFIGURATION, model: 'test-model',
|
||||
tool_approval_mode: 'always_trust' as const, max_execution_steps: 70, max_output_tokens: 7200, max_run_seconds: 180 };
|
||||
const configured = { ...draft, configuration };
|
||||
api.list.mockResolvedValue({ agents: [configured], next_cursor: null });
|
||||
const base = api.call.getMockImplementation()!;
|
||||
api.call.mockImplementation(async (operation, input) => operation === 'saveBudget' ? { ...input, daily_committed_points: '0.00' } : base(operation, input));
|
||||
api.call.mockImplementation(async (operation, input) => operation === 'catalog' ? {
|
||||
models: [{ id: 'test-model', name: '原模型' }, { id: 'another-model', name: '新模型' }],
|
||||
resources: { tools: [{ key: 'writing-tool', name: '文章整理工具' }] }, pricing: null,
|
||||
} : base(operation, input));
|
||||
api.save.mockImplementation(async (_slug, input) => ({ ...configured, ...input, draft_revision: 2 }));
|
||||
open();
|
||||
fireEvent.click(await screen.findByRole('button', { name: '继续制作', exact: true }));
|
||||
fireEvent.change(screen.getByLabelText('提示词'), { target: { value: '未保存的指令' } });
|
||||
expect(screen.queryByLabelText('消息')).not.toBeInTheDocument();
|
||||
expect(screen.getByLabelText('提示词')).toHaveValue('未保存的指令');
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: '高级设置' }), { button: 0, ctrlKey: false });
|
||||
const budget = screen.getByLabelText('每日上限(词元点数)');
|
||||
await waitFor(() => expect(budget).toBeEnabled());
|
||||
fireEvent.change(budget, { target: { value: '12' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '保存费用上限' }));
|
||||
await waitFor(() => expect(api.call).toHaveBeenCalledWith('saveBudget', expect.objectContaining({ daily_limit_points: '12' })));
|
||||
await waitFor(() => expect(screen.getByLabelText('模型')).toBeEnabled());
|
||||
fireEvent.change(screen.getByLabelText('模型'), { target: { value: 'another-model' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '选择工具箱', exact: true }));
|
||||
fireEvent.click(screen.getByRole('checkbox', { name: '文章整理工具', exact: true }));
|
||||
expect(screen.queryByLabelText('最多执行步数')).not.toBeInTheDocument();
|
||||
expect(screen.queryByLabelText('每日上限(词元点数)')).not.toBeInTheDocument();
|
||||
expect(api.save).not.toHaveBeenCalled();
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: '介绍与提示词', exact: true }), { button: 0, ctrlKey: false });
|
||||
expect(screen.getByLabelText('提示词')).toHaveValue('未保存的指令');
|
||||
expect(screen.getByRole('button', { name: '保存草稿' })).toBeEnabled();
|
||||
expect(api.call.mock.calls.some(([operation]) => ['threads', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
fireEvent.click(screen.getByRole('button', { name: '保存草稿' }));
|
||||
await screen.findByRole('button', { name: '已保存' });
|
||||
expect(api.save).toHaveBeenCalledWith(draft.slug, expect.objectContaining({
|
||||
system_prompt: '未保存的指令', configuration: { ...configuration, model: 'another-model', tools: ['writing-tool'] },
|
||||
}));
|
||||
expect(api.call.mock.calls.some(([operation]) => ['budget', 'saveBudget', 'resources', 'threads', 'preview', 'submit'].includes(operation))).toBe(false);
|
||||
});
|
||||
|
||||
it('saves a cleared model selection without choosing another model or starting a preview', async () => {
|
||||
|
||||
Reference in new issue
Block a user