openpencil/tests/e2e/chat/reasoning.spec.ts
Danila Poyarkov af18eec514
fix(ai): polish chat history and stabilize chat tests (#923)
* fix(ai): confirm deleting a conversation in the standard dialog

Deleting a conversation asked inside the chat panel's header, unlike every other destructive confirmation, which uses AppConfirmationDialog. It now opens that dialog, which names the conversation; Cancel keeps it and Delete removes it.

* feat(ai): dim a reverted reply's content

A reverted reply still showed its tool cards with their success marks and its text as if the edits were there; only the line below said otherwise. Its content is now dimmed, while the Changes reverted or Restore changes line and the other actions stay at full strength.

* ci: typecheck the test suites in Code quality

bun run check runs check:test-types, but PR CI did not, so tests that no longer type-checked could merge and break bun run check on master, as the grid fixtures from #866 did. It runs as a step of Code quality, which already builds the package declarations it needs; the check takes about two seconds, less than a separate job's setup.

* test(ai): time the reasoning auto-close with the fake clock

The test slept 1200 ms of real time past the 1000 ms auto-close to show that a manually opened block stays open, which was timing-dependent under load. It now advances Playwright's clock past the timer. With manual opening ignored, it fails.

* test(ai): skip file identity on Playwright's bundled Chromium on macOS

There, reading a FileSystemFileHandle back from IndexedDB closes the page before any app code runs, so the test always failed locally on a Mac. Installed Google Chrome on the same machine reads and compares the handle correctly, and the app's resolveFile returns one ID for twelve concurrent calls there. The skip is limited to the bundled build on macOS.

* fix(settings): keep a model picker open while the editor slides in

The models panel focused the editor's first field after its enter transition, even when focus had already moved into the editor, closing a picker opened during the animation. It now leaves focus alone once it has moved since the editor opened.

* test: serve a fixed model catalog and wait for the editor before Settings shortcuts

Chat tests fetched the live models.dev catalog, so the model list changed under them; they now get a small fixed one. The credentials test pressed the Settings shortcut before the editor was ready.

* fix(settings): move drill-in focus with Reka's FocusScope

The drill-in focused the detail's first field after its slide-in ended, found by querying the DOM, and restored focus by hand, so a picker opened during the slide closed. FocusScope now focuses the detail as it mounts and returns focus to what opened it. A caller can prevent open-auto-focus to focus its own field, which the models panel does for the profile name through the editor's exposed focus().

* test(ai): answer the Vision model's request in chat tests

A message with images is analyzed by the Vision model, which calls OpenRouter directly rather than the mocked chat transport. With the test key the request failed, and since #916 a failure before dispatch takes the message back, so the WebKit history test never got a reply. The chat fixture now answers that request with fixed findings.

* test(ai): check that deletion persists and reverted replies dim

The delete test passed even if the conversation stayed in storage, since the panel clears its messages before the store removes it; it now reloads and checks the history. The revert test checked only data-reverted; it now checks the rendered opacity too.
2026-10-07 09:53:05 +00:00

94 lines
3.9 KiB
TypeScript

import { test, expect } from '#tests/helpers/chat/fixture'
import { finishReasoning, installReasoningTransport } from '#tests/helpers/chat/reasoning'
test('expand while thinking auto-collapses but preserves manual opening', async ({
configuredChat: chat,
page
}) => {
await page.getByTestId('provider-settings-trigger').click()
await page.getByRole('combobox', { name: 'Reasoning display' }).click()
await page.getByRole('option', { name: 'Expand while thinking', exact: true }).click()
await page.getByTestId('app-settings-done').click()
await installReasoningTransport(page)
await chat.submit('Inspect the layout')
const trigger = page.locator('[data-slot="chat-reasoning-trigger"]').last()
await expect(trigger).toHaveAttribute('aria-expanded', 'true')
await finishReasoning(page)
await expect(trigger).toHaveAttribute('aria-expanded', 'false')
await chat.submit('Inspect it again')
await expect(trigger).toHaveAttribute('aria-expanded', 'true')
await trigger.click()
await trigger.click()
// Time the auto-close instead of sleeping past it.
await page.clock.install()
await finishReasoning(page)
await expect(chat.assistantMessage()).toContainText('Finished inspecting')
await page.clock.runFor(1500)
await expect(trigger).toHaveAttribute('aria-expanded', 'true')
})
test('collapsed reasoning respects reduced motion and does not scroll old content to the bottom', async ({
configuredChat: chat,
page
}) => {
await page.emulateMedia({ reducedMotion: 'reduce' })
await chat.submit('Show reasoning')
const trigger = page.locator('[data-slot="chat-reasoning-trigger"]').first()
await expect(trigger).toHaveAttribute('aria-expanded', 'false')
await chat.submit(Array.from({ length: 60 }, (_, i) => `Follow-up line ${i}`).join('\n'))
await expect(chat.assistantMessage()).toBeVisible()
const viewport = page.getByTestId('chat-panel').locator('[data-reka-scroll-area-viewport]')
await viewport.evaluate((element) => {
element.scrollTop = 0
})
await trigger.click()
await expect(trigger).toHaveAttribute('aria-expanded', 'true')
const content = page.locator('[data-slot="chat-reasoning-content"]').first()
expect(await content.evaluate((element) => getComputedStyle(element).animationName)).toBe('none')
await expect
.poll(() =>
viewport.evaluate(
(element) => element.scrollHeight - element.scrollTop - element.clientHeight
)
)
.toBeGreaterThan(500)
expect(await viewport.evaluate((element) => element.scrollTop)).toBeLessThan(30)
await page.getByRole('button', { name: 'Jump to latest' }).click()
await expect
.poll(() =>
viewport.evaluate(
(element) => element.scrollHeight - element.scrollTop - element.clientHeight
)
)
.toBeLessThan(3)
})
test('reasoning preferences use AI settings and persist across reload', async ({
configuredChat: chat,
page
}) => {
await page.getByTestId('provider-settings-trigger').click()
const display = page.getByRole('combobox', { name: 'Reasoning display' })
await expect(display).toContainText('Collapsed by default')
await display.click()
await page.getByRole('option', { name: 'Expanded by default', exact: true }).click()
await page.getByTestId('app-settings-done').click()
await chat.submit('Show your reasoning')
const trigger = page.locator('[data-slot="chat-reasoning-trigger"]')
await expect(trigger).toHaveAttribute('aria-expanded', 'true')
await trigger.click()
await expect(trigger).toHaveAttribute('aria-expanded', 'false')
await expect
.poll(() =>
page
.locator('[data-slot="chat-reasoning-content"]')
.evaluate((element) => getComputedStyle(element).animationName)
)
.toBe('collapsible-up')
await expect(page.locator('[data-slot="chat-reasoning-content"]')).toBeHidden()
await page.reload()
await chat.chatTab.click()
await page.getByTestId('provider-settings-trigger').click()
await expect(display).toContainText('Expanded by default')
})