LibreChat/e2e/specs/mock/scenarios/composer-context.spec.ts
Marco Beretta 749c1a3943
📌 fix: Keep the Composer Thinking Level for the Rest of the Conversation (#17497)
* fix: Label Composer Thinking Levels and State the One-Shot Scope

* test: Cover Composer Thinking Labels and One-Shot Scope in E2E

* test: Cover Thinking Focus for Option Lists Without Auto

* test: Wait for the Thinking Popover's Open Focus Before Arrow Keys

* test: Match the High Effort Radio Exactly

* fix: Keep the Composer Thinking Level for the Rest of the Conversation

* fix: Keep a Queued Turn's Picked Level on the Turns Queued After It

* test: Name the Numeric Reasoning Control by Its Thinking Label

* fix: Name the Queued Turn's Level on the Thinking Button

* test: Dismiss the Thinking Tooltip Before Typing on a Phone

* fix: Respect Enforced Specs and Parameters Edits Over the Inherited Thinking Level

* test: Expect the Model Spec Enforcement Flag in Chat Settings

* fix: Keep a Queued Turn Off a Level Its Target No Longer Runs

* fix: Record the Target a Queued Turn's Level Belongs To

* refactor: Inherit the Thinking Level on the Server

* perf: Answer the Branch Level Lookup Without Tree Links When Nothing Was Picked

* fix: Respect the Thinking Switch and Held Queue Rows Over the Inherited Level

* fix: Read the Branch Level Once and Inherit Only on Fresh Turns

* fix: Keep a Parameters Thinking Edit From Turning Thinking On

* fix: Withdraw a Staged Thinking Level When Thinking Is Switched Off

* fix: Scope the Thinking Switch Transition to the Conversation

* test: Drop the One-Shot Thinking Scenario the Conversation Level Replaces
2026-10-28 19:11:07 +01:00

145 lines
5.8 KiB
TypeScript

import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import type { TMessage } from 'librechat-data-provider';
import {
MOCK_ENDPOINTS,
NEW_CHAT_PATH,
getAccessToken,
messagesView,
requestJson,
selectMockEndpoint,
sendMessageAndWaitForCompletion,
uniqueName,
} from '../helpers';
import { deleteConversations, deleteMessagesByConversation } from '../db';
async function cleanupConversation(page: Page) {
const conversationId = /\/c\/([^/?]+)/.exec(page.url())?.[1];
if (conversationId == null || conversationId === 'new') {
return;
}
await deleteMessagesByConversation([conversationId]);
await deleteConversations([conversationId]);
}
async function uploadViaComposerPalette(
page: Page,
file: { name: string; mimeType: string; content: string },
) {
await page.getByRole('button', { name: 'Attach and tools' }).click();
const palette = page.getByRole('dialog', { name: 'Attach and tools' });
const localUpload = palette.getByRole('button', {
name: /^(From Local Computer|Upload to Provider)$/,
});
await expect(localUpload).toBeVisible();
const [fileChooser] = await Promise.all([page.waitForEvent('filechooser'), localUpload.click()]);
const uploadResponse = page.waitForResponse(
(response) =>
new URL(response.url()).pathname === '/api/files' && response.request().method() === 'POST',
{ timeout: 30000 },
);
await fileChooser.setFiles({
name: file.name,
mimeType: file.mimeType,
buffer: Buffer.from(file.content, 'utf8'),
});
return uploadResponse;
}
test.describe('composer context', () => {
test('selecting a built-in tool leaves a removable active chip @scenario:selected-tool-shows-as-an-active-composer-chip', async ({
page,
}) => {
test.setTimeout(90000);
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
const palette = page.getByRole('button', { name: 'Attach and tools' });
await palette.click();
const dialog = page.getByRole('dialog', { name: 'Attach and tools' });
const memoryRow = dialog.getByRole('button', { name: 'Memory', exact: true });
await expect(memoryRow).toBeVisible();
await memoryRow.click();
await expect(memoryRow).toHaveAttribute('aria-pressed', 'true');
const activeChip = page.getByTestId('composer-active-builtin').filter({ hasText: 'Memory' });
await expect(activeChip).toBeVisible();
await page.keyboard.press('Escape');
await expect(dialog).toBeHidden();
await expect(activeChip).toContainText('Memory');
await activeChip.getByRole('button', { name: 'Remove Memory', exact: true }).click();
await expect(activeChip).toBeHidden();
await palette.click();
const reopenedDialog = page.getByRole('dialog', { name: 'Attach and tools' });
await expect(
reopenedDialog.getByRole('button', { name: 'Memory', exact: true }),
).toHaveAttribute('aria-pressed', 'false');
});
test('attached files stage in the tray and only retained files ride with the message @scenario:attached-file-stages-in-the-tray-and-rides-with-the-message', async ({
page,
}) => {
test.setTimeout(120000);
try {
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[1]);
const retainedName = `${uniqueName('retained')}.md`;
const removedName = `${uniqueName('removed')}.md`;
const tray = page.getByTestId('composer-tray');
const retainedUpload = await uploadViaComposerPalette(page, {
name: retainedName,
mimeType: 'text/markdown',
content: '# retained staged file\n',
});
expect(retainedUpload.ok()).toBeTruthy();
await expect(tray).toBeVisible();
await expect(tray.getByRole('button', { name: retainedName, exact: true })).toBeVisible();
const removedUpload = await uploadViaComposerPalette(page, {
name: removedName,
mimeType: 'text/markdown',
content: '# removed before send\n',
});
expect(removedUpload.ok()).toBeTruthy();
await expect(tray.getByRole('button', { name: removedName, exact: true })).toBeVisible();
const removedCard = tray
.getByRole('button', { name: removedName, exact: true })
.locator('..');
await removedCard.getByRole('button', { name: 'Remove file', exact: true }).click();
await expect(tray.getByRole('button', { name: removedName, exact: true })).toBeHidden();
await expect(tray.getByRole('button', { name: retainedName, exact: true })).toBeVisible();
await sendMessageAndWaitForCompletion(page, 'E2E retained staged attachment');
await expect(
messagesView(page).getByRole('button', { name: retainedName, exact: true }),
).toBeVisible();
await expect(
messagesView(page).getByRole('button', { name: removedName, exact: true }),
).toHaveCount(0);
const conversationId = /\/c\/([^/?]+)/.exec(page.url())?.[1];
expect(conversationId, 'sent attachment conversation should have an id').toBeTruthy();
const messages = await requestJson<TMessage[]>(page, {
path: `/api/messages/${encodeURIComponent(conversationId as string)}`,
token: await getAccessToken(page),
});
const sentUserMessages = messages.filter((message) => message.isCreatedByUser === true);
const sentMessage = sentUserMessages[sentUserMessages.length - 1];
expect(sentMessage, 'the sent user message should persist').toBeDefined();
const sentFiles = [
...(sentMessage?.files ?? []),
...(sentMessage?.attachments ?? []),
] as Array<{ filename?: string }>;
expect(sentFiles.map((file) => file.filename)).toContain(retainedName);
expect(sentFiles.map((file) => file.filename)).not.toContain(removedName);
} finally {
await cleanupConversation(page);
}
});
});