diff --git a/apps/e2e/support/analyst-thread.ts b/apps/e2e/support/analyst-thread.ts index a3466055..f840e391 100644 --- a/apps/e2e/support/analyst-thread.ts +++ b/apps/e2e/support/analyst-thread.ts @@ -7,7 +7,8 @@ import { expect } from './fixtures.ts'; * and has neither /system/analyst/ask nor /ask/stream. So the browser says the installation has * one, the project settings say whether external AI is on (nothing is stored), and /ask is * answered in the browser with synthetic replies. /ask/stream is left to the server, whose 404 - * makes Inicio fall back to /ask (T21), unless a spec fakes the stream itself. + * makes Inicio fall back to /ask (T21), unless a spec fakes the stream itself; `fakeAnalyst` declares + * that 404 in the browser, because the Go API does serve the stream. */ export type Source = { n: number; module: string; id: string; title: string }; @@ -48,6 +49,13 @@ export const fakeAnalyst = async (page: Page, { externalAi }: { externalAi: bool await route.fulfill({ response, json: { ...settings, external_ai: { enabled: externalAi } } }); }); await page.route('**/system/analyst', (route) => route.fulfill({ json: { available: true } })); + // Inicio falls back from the stream to /ask when the stream answers 404. The TypeScript API has + // no stream route at all; the Go API serves one (and says no analyst is configured), so the + // fallback is declared here to keep these specs the same on both runtimes. A spec that fakes + // the stream registers its own route afterwards, and Playwright's latest route wins. + await page.route(`**${STREAM_PATH}`, (route) => + route.fulfill({ status: 404, json: { detail: 'Not Found' } }), + ); }; /** The question a request to /ask carries. */ diff --git a/apps/e2e/tests/analyst-answer.mobile.spec.ts b/apps/e2e/tests/analyst-answer.mobile.spec.ts index e3275da3..5b7c2436 100644 --- a/apps/e2e/tests/analyst-answer.mobile.spec.ts +++ b/apps/e2e/tests/analyst-answer.mobile.spec.ts @@ -1,5 +1,6 @@ import { analyzeAccessibility } from '../support/accessibility.ts'; import { DEFAULT_SCOPE, expect, signInToProject, test } from '../support/fixtures.ts'; +import { fakeAnalyst } from '../support/analyst-thread.ts'; /* * The Inicio analyst's answer on a phone (odd/archive/agentic-analyst.md T1d, T2): text, sources and @@ -58,15 +59,7 @@ for (const width of [360, 412]) { }) => { await page.emulateMedia({ colorScheme, reducedMotion: 'reduce' }); await page.setViewportSize({ width, height: 800 }); - await page.route('**/system/v4/settings', async (route) => { - const response = await route.fetch(); - const settings = (await response.json()) as Record; - await route.fulfill({ response, json: { ...settings, external_ai: { enabled: true } } }); - }); - // This e2e API has no analyst; the browser says the installation has one. - await page.route('**/system/analyst', (route) => - route.fulfill({ json: { available: true } }), - ); + await fakeAnalyst(page, { externalAi: true }); await page.route('**/system/analyst/ask', (route) => route.fulfill({ json: reply })); await signInToProject(page, admin, DEFAULT_SCOPE); await page.goto('/inicio'); diff --git a/apps/e2e/tests/inicio-phone.mobile.spec.ts b/apps/e2e/tests/inicio-phone.mobile.spec.ts index d26a0bba..ca6ca537 100644 --- a/apps/e2e/tests/inicio-phone.mobile.spec.ts +++ b/apps/e2e/tests/inicio-phone.mobile.spec.ts @@ -1,5 +1,6 @@ import type { Locator, Page } from '@playwright/test'; import { DEFAULT_SCOPE, expect, signInToProject, test } from '../support/fixtures.ts'; +import { fakeAnalyst } from '../support/analyst-thread.ts'; import { smallTargets } from './target-size.ts'; /* @@ -23,12 +24,7 @@ const box = async (locator: Locator) => { }; const askOnPhone = async (page: Page, admin: { username: string; password: string }) => { - await page.route('**/system/v4/settings', async (route) => { - const response = await route.fetch(); - const settings = (await response.json()) as Record; - await route.fulfill({ response, json: { ...settings, external_ai: { enabled: true } } }); - }); - await page.route('**/system/analyst', (route) => route.fulfill({ json: { available: true } })); + await fakeAnalyst(page, { externalAi: true }); await page.route('**/system/analyst/ask', (route) => route.fulfill({ json: reply })); await signInToProject(page, admin, DEFAULT_SCOPE); await page.goto('/inicio');