Measured against the gateway this deployment actually uses (ai.lago.dev), a
"Reply with OK" request comes back with usage.completion_tokens_details: {} --
the provider does not report a reasoning counter at all. Thinking is
verifiably off there (2 completion tokens, 424 ms, versus ~235 tokens and
~3.5x latency when on), but reasoning_tokens is undefined, not 0.
The verdict had two states, so a healthy production connection rendered amber
with "the model is still thinking" -- the button would have reported a working
configuration as broken. The reasoning verdict is now three-state:
- reported 0 -> reasoning_disabled: true, green
- not reported -> reasoning_tokens: null, no warning, neutral card that
says it cannot be confirmed from the usage block
- reported and > 0 -> amber + the existing warning
Only a reported 0 asserts reasoning_disabled, so the UI still never claims
thinking is off without evidence.
Sidecar 34 -> 35 tests (all three unreported shapes assert no warning); new
e2e/tests/llm-connection-test.spec.ts, 6 tests, covering the three verdict
tones, the failure case, the dirty-form lock and the in-flight state.
Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
157 lines
8.5 KiB
TypeScript
157 lines
8.5 KiB
TypeScript
import { test, expect, type Page, type Route } from '@playwright/test';
|
|
|
|
const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001';
|
|
const eventId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
|
|
const user = { id: '99999999-9999-4999-8999-999999999999', email: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
|
|
|
|
/**
|
|
* The "Validate AI connection" button in Settings.
|
|
*
|
|
* The verdict has three reasoning states and they must not be conflated, because
|
|
* the gateway in production (ai.lago.dev) answers with
|
|
* `completion_tokens_details: {}` — it reports NO reasoning counter at all.
|
|
* Treating "not reported" the same as "reported and non-zero" tells an admin that
|
|
* a working configuration is broken. So: 0 = green, absent = neutral with no
|
|
* warning, > 0 = amber with a warning.
|
|
*/
|
|
|
|
const storedSettings = { endpoint: 'https://ai.lago.dev/v1/chat/completions', model: 'Qwen3.8', has_api_key: true };
|
|
|
|
type Verdict = Record<string, unknown>;
|
|
type Harness = {
|
|
verdict: Verdict;
|
|
testCalls: { method: string; auth: string }[];
|
|
settingsDelayMs: number;
|
|
};
|
|
|
|
const ok = (tokens: number | null | undefined): Verdict => ({
|
|
ok: true, model: 'Qwen3.8', endpoint: storedSettings.endpoint, latency_ms: 424,
|
|
reasoning_disabled: tokens === 0,
|
|
reasoning_tokens: tokens === undefined ? null : tokens,
|
|
content: 'OK', warning: tokens !== null && tokens !== undefined && tokens > 0
|
|
? 'The connection works but reasoning tokens were reported, so thinking is still enabled — summaries will be slow and costly.'
|
|
: null,
|
|
error: null,
|
|
});
|
|
|
|
async function openAdmin(page: Page, h: Harness) {
|
|
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
|
|
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'r', expires_in: 3600, token_type: 'bearer' };
|
|
await page.route('**/auth/v1/**', (r) => r.fulfill({ json: new URL(r.request().url()).pathname.endsWith('/user') ? user : session }));
|
|
await page.route('**/rest/v1/**', async (route: Route) => {
|
|
const u = new URL(route.request().url());
|
|
const t = u.pathname.split('/').pop();
|
|
if (t === 'contacts') return route.fulfill({ json: u.searchParams.has('email') ? { email: user.email, full_name: 'Admin User', is_admin: true } : [] });
|
|
if (t === 'events') return route.fulfill({ json: u.searchParams.has('is_active') ? { id: eventId, name: 'Test Conf', is_active: true, badge_copies: 1 } : [{ id: eventId, name: 'Test Conf', is_active: true, badge_copies: 1 }] });
|
|
return route.fulfill({ json: [] });
|
|
});
|
|
await page.route('**/sidecar/llm-settings', async (route: Route) => {
|
|
if (h.settingsDelayMs) await new Promise((r) => setTimeout(r, h.settingsDelayMs));
|
|
return route.fulfill({ json: storedSettings });
|
|
});
|
|
await page.route('**/sidecar/llm-test', async (route: Route) => {
|
|
h.testCalls.push({ method: route.request().method(), auth: route.request().headers().authorization });
|
|
return route.fulfill({ json: h.verdict });
|
|
});
|
|
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=r&type=magiclink`);
|
|
await expect(page.locator('.nav')).toBeVisible();
|
|
await page.locator('.nav').getByRole('button', { name: /Settings/ }).click();
|
|
await expect(page.getByTestId('llm-test-button')).toBeVisible();
|
|
}
|
|
|
|
const result = (page: Page) => page.getByTestId('llm-test-result');
|
|
|
|
test('a reported zero reasoning token count reads as a clean pass', async ({ page }) => {
|
|
const h: Harness = { verdict: ok(0), testCalls: [], settingsDelayMs: 0 };
|
|
await openAdmin(page, h);
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(result(page)).toBeVisible();
|
|
await expect(result(page)).toHaveClass(/good/);
|
|
await expect(result(page)).not.toHaveClass(/warn|neutral|bad/);
|
|
await expect(page.getByTestId('llm-test-headline')).toContainText('Connection works');
|
|
await expect(page.getByTestId('llm-test-headline')).toContainText('424 ms');
|
|
await expect(page.getByTestId('llm-test-reasoning')).toContainText('Reasoning tokens: 0');
|
|
await expect(page.getByTestId('llm-test-warning')).toHaveCount(0);
|
|
});
|
|
|
|
test('an endpoint that reports no reasoning counter is not flagged as a problem', async ({ page }) => {
|
|
// This is the production shape: usage present, completion_tokens_details empty.
|
|
const h: Harness = { verdict: ok(null), testCalls: [], settingsDelayMs: 0 };
|
|
await openAdmin(page, h);
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(result(page)).toBeVisible();
|
|
await expect(result(page)).toHaveClass(/neutral/);
|
|
await expect(result(page)).not.toHaveClass(/warn|bad/);
|
|
await expect(page.getByTestId('llm-test-headline')).toContainText('Connection works');
|
|
await expect(page.getByTestId('llm-test-headline')).not.toContainText('still thinking');
|
|
await expect(page.getByTestId('llm-test-warning')).toHaveCount(0);
|
|
// It must say it cannot confirm, rather than asserting thinking is off.
|
|
await expect(page.getByTestId('llm-test-reasoning')).toContainText('does not report a reasoning-token count');
|
|
});
|
|
|
|
test('reported non-zero reasoning tokens stay amber with the warning', async ({ page }) => {
|
|
const h: Harness = { verdict: ok(235), testCalls: [], settingsDelayMs: 0 };
|
|
await openAdmin(page, h);
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(result(page)).toHaveClass(/warn/);
|
|
await expect(page.getByTestId('llm-test-headline')).toContainText('still thinking');
|
|
await expect(page.getByTestId('llm-test-warning')).toContainText('thinking is still enabled');
|
|
await expect(page.getByTestId('llm-test-reasoning')).toContainText('Reasoning tokens: 235');
|
|
});
|
|
|
|
test('a failed connection reports the provider error and stays usable', async ({ page }) => {
|
|
const h: Harness = {
|
|
verdict: { ok: false, model: 'Qwen3.8', endpoint: storedSettings.endpoint, latency_ms: 5000, reasoning_disabled: false, reasoning_tokens: null, content: '', warning: null, error: 'HTTP 503: upstream unavailable' },
|
|
testCalls: [], settingsDelayMs: 0,
|
|
};
|
|
await openAdmin(page, h);
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(result(page)).toHaveClass(/bad/);
|
|
await expect(page.getByTestId('llm-test-headline')).toContainText('Connection failed');
|
|
await expect(page.getByTestId('llm-test-error')).toContainText('HTTP 503');
|
|
// No result should render the reasoning line at all.
|
|
await expect(page.getByTestId('llm-test-reasoning')).toHaveCount(0);
|
|
await expect(page.getByTestId('llm-test-button')).toBeEnabled();
|
|
});
|
|
|
|
test('the button waits for the request and is disabled while unsaved changes exist', async ({ page }) => {
|
|
const h: Harness = { verdict: ok(0), testCalls: [], settingsDelayMs: 0 };
|
|
await openAdmin(page, h);
|
|
// Editing a stored field must block the test: the API key never reaches the
|
|
// browser, so only what is already saved can be exercised.
|
|
const endpoint = page.locator('#llm-endpoint');
|
|
await expect(endpoint).toHaveValue(storedSettings.endpoint);
|
|
await endpoint.fill('https://example.test/v1/chat/completions');
|
|
await expect(page.getByTestId('llm-test-dirty')).toBeVisible();
|
|
await expect(page.getByTestId('llm-test-button')).toBeDisabled();
|
|
|
|
await endpoint.fill(storedSettings.endpoint);
|
|
await expect(page.getByTestId('llm-test-dirty')).toHaveCount(0);
|
|
await expect(page.getByTestId('llm-test-button')).toBeEnabled();
|
|
|
|
// In flight: progress shown, controls not double-clickable.
|
|
let release: (v: Verdict) => void = () => {};
|
|
await page.unroute('**/sidecar/llm-test');
|
|
await page.route('**/sidecar/llm-test', async (route: Route) => {
|
|
h.testCalls.push({ method: route.request().method(), auth: route.request().headers().authorization });
|
|
await new Promise<Verdict>((res) => { release = res; });
|
|
return route.fulfill({ json: h.verdict });
|
|
});
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(page.getByTestId('llm-test-progress')).toBeVisible();
|
|
await expect(page.getByTestId('llm-test-button')).toBeDisabled();
|
|
await release(ok(0));
|
|
await expect(page.getByTestId('llm-test-progress')).toHaveCount(0);
|
|
await expect(result(page)).toBeVisible();
|
|
});
|
|
|
|
test('the test is a POST carrying the admin token', async ({ page }) => {
|
|
const h: Harness = { verdict: ok(0), testCalls: [], settingsDelayMs: 0 };
|
|
await openAdmin(page, h);
|
|
await page.getByTestId('llm-test-button').click();
|
|
await expect(result(page)).toBeVisible();
|
|
expect(h.testCalls).toHaveLength(1);
|
|
expect(h.testCalls[0].method).toBe('POST');
|
|
expect(h.testCalls[0].auth).toMatch(/^Bearer /);
|
|
});
|