LibreChat/e2e/specs/mock/scenarios/tool-timer.spec.ts
Danny Avila 559eadfdcb
🧪 test: Close Two Input Timing Gaps Behind Intermittent Tool Timer and Pinned Drag Failures (#18074)
* ⏱️ test: Let the Composer Palette Finish Closing Before the Tool Timer Freezes the Clock

`tool-timer.spec.ts` closes the composer palette with Escape and then calls
`page.clock.setFixedTime`, which installs Playwright's clock. From that point
every timer the page starts is run by the clock, one callback per task, and
the agent stream that follows queues a zero-delay timeout for each query-cache
notification, so the clock runs seconds behind.

The palette is still closing when the clock is installed. Its popover unmounts
from a 123 ms leave timer that is started two animation frames after Escape.
When the install lands inside those two frames the timer belongs to the clock
and waits behind the notification backlog: the popover stays mounted at zero
opacity over the transcript and takes the click meant for the tool disclosure
for the five seconds the tool runs. The disclosure then leaves with the tool
and the click waits out the test's 120 s timeout.

Wait for the palette dialog to unmount before reading the start time and
freezing the clock.

* 🧲 test: Deliver a Hover Frame Before a Pinned Row Drag Is Released

`dragRowOnto` sends its whole pointer path, release included, in about 25 ms.
react-dnd's HTML5 backend delivers hover to drop targets once per animation
frame, and a target's hover callback reads the pointer offset the previous
hover recorded, so a release is judged against where the pointer was when a
frame last ran. When no frame runs between the pointer crossing the hovered
row's midpoint and the release, the last recorded offset is the one from
entering the row, in its lower half: the swap is refused and the list keeps
its order.

Only the reorder in `a pinned chat cannot be dragged through a pinned model`
depends on that reading. The other drags in the file end in a drop handler
that reads no offset.

Wait for an animation frame after each of the three settling moves, so the
hover carrying the final position has been delivered before the release.
2026-11-12 07:20:21 -05:00

55 lines
2.8 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { NEW_CHAT_PATH, messagesView, modelSelectorTrigger, sendMessage } from '../helpers';
test('a running tool includes hidden time before and after expansion @scenario:running-tool-timer-keeps-hidden-time', async ({
page,
}) => {
test.setTimeout(120_000);
const label = `timer-${Date.now()}`;
await page.goto(NEW_CHAT_PATH);
const modelSelector = modelSelectorTrigger(page);
await modelSelector.click();
await page.getByRole('option', { name: 'Mock Provider F', exact: true }).click();
/** Mobile includes the nested Pin action in the option's accessible name. */
await page.getByRole('option', { name: /^mock-model-f(?: Pin)?$/ }).click();
await expect(modelSelector).toContainText('mock-model-f');
await expect(modelSelector).toHaveAttribute('aria-expanded', 'false');
await page.getByRole('button', { name: 'Attach and tools' }).click();
await page
.getByRole('dialog', { name: 'Attach and tools' })
.getByRole('button', { name: /^E2E Memory\b/ })
.click();
await page.keyboard.press('Escape');
/** `setFixedTime` hands every timer the page starts from then on to Playwright's clock, which
* runs one per task and falls seconds behind once the stream's cache notifications queue up.
* The palette is still closing here; a leave timer started after the install waits behind
* them, and the invisible popover covers the transcript and takes the click meant for the
* tool row. It unmounts when the leave ends, so wait for that on the page's own clock. */
await expect(page.getByRole('dialog', { name: 'Attach and tools' })).toHaveCount(0);
const start = await page.evaluate(() => Date.now());
await page.clock.setFixedTime(start);
await sendMessage(page, `E2E_INTERRUPT_TOOL_REPLY:${label}`);
const view = messagesView(page);
const card = view.getByTestId('activity-phase-card').last();
const disclosure = card.locator('button[aria-expanded]').first();
await expect(disclosure).toContainText(/Running/);
await expect(disclosure).toHaveAttribute('aria-expanded', 'false');
const row = card.locator(`[data-tool-call-id="call_interrupt_slow_${label}"]`);
await expect(row).toHaveCount(0);
await page.clock.setFixedTime(start + 8_000);
await disclosure.click();
const timer = row.getByTestId('stream-elapsed');
await expect(timer).toHaveText(/^\d+s$/);
const before = Number.parseInt((await timer.innerText()).trim(), 10);
expect(before).toBeGreaterThanOrEqual(8);
await disclosure.click();
await expect(row).toHaveCount(0);
await page.clock.setFixedTime(start + 11_000);
await disclosure.click();
await expect(timer).toBeVisible();
expect(Number.parseInt((await timer.innerText()).trim(), 10)).toBeGreaterThanOrEqual(before + 3);
await page.getByTestId('stop-generation-button').click();
});