LibreChat/e2e/specs/mock/scenarios/composer-thinking-level.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

114 lines
4.4 KiB
TypeScript

import { expect, test } from '@playwright/test';
import type { Page, Request } from '@playwright/test';
import type { TMessage } from 'librechat-data-provider';
import {
fetchJson,
MOCK_ENDPOINTS,
NEW_CHAT_PATH,
getAccessToken,
selectMockEndpoint,
sendMessageAndWaitForCompletion,
} from '../helpers';
/* Mock Provider A advertises Anthropic's `effort` enum: Auto, then Low through Max. */
const trigger = (page: Page) => page.getByTestId('composer-thinking-button');
const popover = (page: Page) => page.getByRole('dialog', { name: /^Thinking: / });
async function openNewChat(page: Page) {
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
await expect(trigger(page)).toHaveAccessibleName('Thinking: Auto');
}
async function pick(page: Page, level: string) {
await trigger(page).click();
await popover(page).getByRole('radio', { name: level, exact: true }).click();
await expect(trigger(page)).toHaveAccessibleName(`Thinking: ${level}`);
await page.keyboard.press('Escape');
await expect(popover(page)).toBeHidden();
/* Focus returns to the trigger, whose tooltip sits over the message field on a phone. */
await page.keyboard.press('Escape');
await expect(page.getByRole('tooltip')).toBeHidden();
}
/** Sends a turn and returns the reasoning override its request carried. */
async function send(page: Page, text: string) {
const [request] = await Promise.all([
page.waitForRequest(
(req: Request) => req.method() === 'POST' && req.url().includes('/api/agents/chat'),
{ timeout: 30000 },
),
sendMessageAndWaitForCompletion(page, `${text}-${Date.now()}`),
]);
return (request.postDataJSON() as { reasoningOverride?: unknown }).reasoningOverride;
}
/** The level the server recorded on each user turn, oldest first. */
async function savedLevels(page: Page) {
const conversationId = new URL(page.url()).pathname.split('/c/')[1];
const messages = await fetchJson<TMessage[]>(
page,
`/api/messages/${encodeURIComponent(conversationId)}`,
await getAccessToken(page),
);
return messages
.filter((message) => message.isCreatedByUser === true)
.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))
.map((message) => message.reasoningOverride?.value ?? null);
}
test.describe('composer thinking level', () => {
test('Thinking level holds for the rest of the conversation @scenario:thinking-level-holds-for-the-conversation', async ({
page,
}) => {
await openNewChat(page);
await pick(page, 'Medium');
expect(await send(page, 'first')).toEqual({ key: 'effort', value: 'medium' });
await expect(trigger(page)).toHaveAccessibleName('Thinking: Medium');
/* Nothing new picked: the server runs and records the branch's level. */
expect(await send(page, 'second')).toBeUndefined();
await expect(trigger(page)).toHaveAccessibleName('Thinking: Medium');
expect(await savedLevels(page)).toEqual(['medium', 'medium']);
});
test('Thinking level survives a reload of the conversation @scenario:thinking-level-survives-reload', async ({
page,
}) => {
await openNewChat(page);
await pick(page, 'High');
expect(await send(page, 'before-reload')).toEqual({ key: 'effort', value: 'high' });
await expect(page).toHaveURL(/\/c\/(?!new)/);
await page.reload();
await expect(trigger(page)).toHaveAccessibleName('Thinking: High');
await send(page, 'after-reload');
expect(await savedLevels(page)).toEqual(['high', 'high']);
});
test('Picking another level replaces it for later messages @scenario:thinking-level-changes-with-a-new-pick', async ({
page,
}) => {
await openNewChat(page);
await pick(page, 'Medium');
expect(await send(page, 'medium')).toEqual({ key: 'effort', value: 'medium' });
await pick(page, 'Low');
expect(await send(page, 'low')).toEqual({ key: 'effort', value: 'low' });
await expect(trigger(page)).toHaveAccessibleName('Thinking: Low');
await send(page, 'still-low');
expect(await savedLevels(page)).toEqual(['medium', 'low', 'low']);
});
test('Thinking popover opens on the Auto toggle in Auto @scenario:thinking-popover-focuses-auto-toggle', async ({
page,
}) => {
await openNewChat(page);
await trigger(page).click();
const autoToggle = popover(page).getByRole('button', { name: 'Auto' });
await expect(autoToggle).toHaveAttribute('aria-pressed', 'true');
await expect(autoToggle).toBeFocused();
});
});