Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/e2e/support/analyst-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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. */
Expand Down
11 changes: 2 additions & 9 deletions apps/e2e/tests/analyst-answer.mobile.spec.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<string, unknown>;
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');
Expand Down
8 changes: 2 additions & 6 deletions apps/e2e/tests/inicio-phone.mobile.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

/*
Expand All @@ -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<string, unknown>;
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');
Expand Down
Loading