|
|
|
|
@@ -0,0 +1,355 @@
|
|
|
|
|
import { expect, test, type Page } from '@playwright/test';
|
|
|
|
|
|
|
|
|
|
import { policyAuthorSession } from '../../src/app/testing';
|
|
|
|
|
import { waitForEntityCards, waitForResults } from './unified-search-fixtures';
|
|
|
|
|
|
|
|
|
|
const liveSearchBaseUrl = process.env['LIVE_ADVISORYAI_SEARCH_BASE_URL']?.trim() ?? '';
|
|
|
|
|
const liveTenant = process.env['LIVE_ADVISORYAI_TENANT']?.trim() || 'test-tenant';
|
|
|
|
|
const liveScopes = process.env['LIVE_ADVISORYAI_SCOPES']?.trim()
|
|
|
|
|
|| 'advisory-ai:view advisory-ai:operate advisory-ai:admin';
|
|
|
|
|
|
|
|
|
|
const mockConfig = {
|
|
|
|
|
authority: {
|
|
|
|
|
issuer: 'https://authority.local',
|
|
|
|
|
clientId: 'stella-ops-ui',
|
|
|
|
|
authorizeEndpoint: 'https://authority.local/connect/authorize',
|
|
|
|
|
tokenEndpoint: 'https://authority.local/connect/token',
|
|
|
|
|
logoutEndpoint: 'https://authority.local/connect/logout',
|
|
|
|
|
redirectUri: 'http://127.0.0.1:4400/auth/callback',
|
|
|
|
|
postLogoutRedirectUri: 'http://127.0.0.1:4400/',
|
|
|
|
|
scope: 'openid profile email ui.read doctor:read advisory-ai:view advisory-ai:operate advisory-ai:admin',
|
|
|
|
|
audience: 'https://doctor.local',
|
|
|
|
|
},
|
|
|
|
|
apiBaseUrls: {
|
|
|
|
|
authority: 'https://authority.local',
|
|
|
|
|
doctor: 'https://doctor.local',
|
|
|
|
|
gateway: 'https://gateway.local',
|
|
|
|
|
},
|
|
|
|
|
quickstartMode: true,
|
|
|
|
|
setup: 'complete',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const oidcConfig = {
|
|
|
|
|
issuer: mockConfig.authority.issuer,
|
|
|
|
|
authorization_endpoint: mockConfig.authority.authorizeEndpoint,
|
|
|
|
|
token_endpoint: mockConfig.authority.tokenEndpoint,
|
|
|
|
|
jwks_uri: 'https://authority.local/.well-known/jwks.json',
|
|
|
|
|
response_types_supported: ['code'],
|
|
|
|
|
subject_types_supported: ['public'],
|
|
|
|
|
id_token_signing_alg_values_supported: ['RS256'],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const doctorSession = {
|
|
|
|
|
...policyAuthorSession,
|
|
|
|
|
scopes: [
|
|
|
|
|
...new Set([
|
|
|
|
|
...policyAuthorSession.scopes,
|
|
|
|
|
'ui.read',
|
|
|
|
|
'admin',
|
|
|
|
|
'ui.admin',
|
|
|
|
|
'health:read',
|
|
|
|
|
'doctor:read',
|
|
|
|
|
'advisory-ai:view',
|
|
|
|
|
'advisory-ai:operate',
|
|
|
|
|
'advisory-ai:admin',
|
|
|
|
|
]),
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockPlugins = {
|
|
|
|
|
plugins: [
|
|
|
|
|
{
|
|
|
|
|
pluginId: 'integration.registry',
|
|
|
|
|
displayName: 'Registry Integration',
|
|
|
|
|
category: 'integration',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
checkCount: 3,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
total: 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockChecks = {
|
|
|
|
|
checks: [
|
|
|
|
|
{
|
|
|
|
|
checkId: 'integration.registry.v2-endpoint',
|
|
|
|
|
name: 'V2 Endpoint Check',
|
|
|
|
|
description: 'Verify OCI registry V2 API endpoint accessibility',
|
|
|
|
|
pluginId: 'integration.registry',
|
|
|
|
|
category: 'integration',
|
|
|
|
|
defaultSeverity: 'fail',
|
|
|
|
|
tags: ['registry', 'oci', 'connectivity'],
|
|
|
|
|
estimatedDurationMs: 5000,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
checkId: 'integration.registry.auth-config',
|
|
|
|
|
name: 'Authentication Config',
|
|
|
|
|
description: 'Validate registry authentication configuration',
|
|
|
|
|
pluginId: 'integration.registry',
|
|
|
|
|
category: 'integration',
|
|
|
|
|
defaultSeverity: 'fail',
|
|
|
|
|
tags: ['registry', 'oci', 'auth'],
|
|
|
|
|
estimatedDurationMs: 3000,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
checkId: 'integration.registry.referrers-api',
|
|
|
|
|
name: 'Referrers API Support',
|
|
|
|
|
description: 'Detect OCI 1.1 Referrers API support',
|
|
|
|
|
pluginId: 'integration.registry',
|
|
|
|
|
category: 'integration',
|
|
|
|
|
defaultSeverity: 'warn',
|
|
|
|
|
tags: ['registry', 'oci', 'referrers'],
|
|
|
|
|
estimatedDurationMs: 4000,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
total: 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
test.describe('Unified Search - Live contextual suggestions', () => {
|
|
|
|
|
test.describe.configure({ mode: 'serial' });
|
|
|
|
|
test.skip(!liveSearchBaseUrl, 'Set LIVE_ADVISORYAI_SEARCH_BASE_URL to a running local AdvisoryAI service.');
|
|
|
|
|
|
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
await ensureLiveServiceHealthy(liveSearchBaseUrl);
|
|
|
|
|
await rebuildLiveIndexes(liveSearchBaseUrl);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
|
await setupDoctorPage(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('shows automatic suggestion chips when the doctor page opens', async ({ page }) => {
|
|
|
|
|
await routeLiveUnifiedSearch(page);
|
|
|
|
|
await openDoctor(page);
|
|
|
|
|
|
|
|
|
|
const searchInput = page.locator('app-global-search input[type="text"]');
|
|
|
|
|
await searchInput.focus();
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('.search__context-title')).toContainText(/doctor diagnostics/i);
|
|
|
|
|
await expect(page.locator('.search__context-token', {
|
|
|
|
|
hasText: /scope:\s+knowledge/i,
|
|
|
|
|
}).first()).toBeVisible();
|
|
|
|
|
await expect(page.locator('.search__suggestions .search__chip', {
|
|
|
|
|
hasText: /database connectivity/i,
|
|
|
|
|
}).first()).toBeVisible();
|
|
|
|
|
await expect(page.locator('.search__suggestions .search__chip', {
|
|
|
|
|
hasText: /oidc readiness/i,
|
|
|
|
|
}).first()).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('clicking a suggestion chip executes a live query and shows a grounded answer', async ({ page }) => {
|
|
|
|
|
const capturedRequests: Array<Record<string, unknown>> = [];
|
|
|
|
|
await routeLiveUnifiedSearch(page, capturedRequests);
|
|
|
|
|
await openDoctor(page);
|
|
|
|
|
|
|
|
|
|
const searchInput = page.locator('app-global-search input[type="text"]');
|
|
|
|
|
await searchInput.focus();
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
await page.locator('.search__suggestions .search__chip', {
|
|
|
|
|
hasText: /database connectivity/i,
|
|
|
|
|
}).first().click();
|
|
|
|
|
|
|
|
|
|
await expect.poll(() =>
|
|
|
|
|
capturedRequests.some((request) => String(request['q'] ?? '').toLowerCase() === 'database connectivity'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
await expect(searchInput).toHaveValue('database connectivity');
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
await waitForEntityCards(page, 1);
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('[data-answer-status="grounded"]')).toBeVisible();
|
|
|
|
|
await expect(page.locator('app-entity-card').first()).toContainText(/postgresql connectivity/i);
|
|
|
|
|
|
|
|
|
|
const matchingRequest = capturedRequests.find((request) =>
|
|
|
|
|
String(request['q'] ?? '').toLowerCase() === 'database connectivity');
|
|
|
|
|
const ambient = matchingRequest?.['ambient'] as Record<string, unknown> | undefined;
|
|
|
|
|
|
|
|
|
|
expect(matchingRequest?.['q']).toBe('database connectivity');
|
|
|
|
|
expect(String(ambient?.['currentRoute'] ?? '')).toContain('/ops/operations/doctor');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('opening a live result promotes a follow-up chip from the last action', async ({ page }) => {
|
|
|
|
|
await routeLiveUnifiedSearch(page);
|
|
|
|
|
await openDoctor(page);
|
|
|
|
|
|
|
|
|
|
const searchInput = page.locator('app-global-search input[type="text"]');
|
|
|
|
|
await searchInput.focus();
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
await page.locator('.search__suggestions .search__chip', {
|
|
|
|
|
hasText: /database connectivity/i,
|
|
|
|
|
}).first().click();
|
|
|
|
|
|
|
|
|
|
await expect(searchInput).toHaveValue('database connectivity');
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
await waitForEntityCards(page, 1);
|
|
|
|
|
await page.locator('app-entity-card').first().click();
|
|
|
|
|
|
|
|
|
|
await expect(page).toHaveURL(/\/ops\/operations\/doctor\?check=check\.core\.db\.connectivity/i);
|
|
|
|
|
|
|
|
|
|
await page.locator('app-global-search input[type="text"]').focus();
|
|
|
|
|
await waitForResults(page);
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('.search__context-token', {
|
|
|
|
|
hasText: /last action:\s+opened result for database connectivity/i,
|
|
|
|
|
}).first()).toBeVisible();
|
|
|
|
|
await expect(page.locator('.search__suggestions .search__chip', {
|
|
|
|
|
hasText: /follow up:\s*database connectivity/i,
|
|
|
|
|
}).first()).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function setupDoctorPage(page: Page): Promise<void> {
|
|
|
|
|
await page.addInitScript((stubSession) => {
|
|
|
|
|
(window as unknown as { __stellaopsTestSession?: unknown }).__stellaopsTestSession = stubSession;
|
|
|
|
|
}, doctorSession);
|
|
|
|
|
|
|
|
|
|
await page.route('**/config.json', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify(mockConfig),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
await page.route('**/platform/envsettings.json', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify(mockConfig),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
await page.route('https://authority.local/**', (route) => {
|
|
|
|
|
const url = route.request().url();
|
|
|
|
|
if (url.includes('/.well-known/openid-configuration')) {
|
|
|
|
|
return route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify(oidcConfig),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (url.includes('/.well-known/jwks.json')) {
|
|
|
|
|
return route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify({ keys: [] }),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return route.abort();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await page.route('**/doctor/api/v1/doctor/plugins**', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify(mockPlugins),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
await page.route('**/doctor/api/v1/doctor/checks**', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify(mockChecks),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
await page.route('**/doctor/api/v1/doctor/run', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify({ runId: 'dr-live-001' }),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
await page.route('**/doctor/api/v1/doctor/run/**', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
status: 200,
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
runId: 'dr-live-001',
|
|
|
|
|
status: 'completed',
|
|
|
|
|
startedAt: '2026-03-07T10:00:00Z',
|
|
|
|
|
completedAt: '2026-03-07T10:00:08Z',
|
|
|
|
|
durationMs: 8000,
|
|
|
|
|
summary: { passed: 2, info: 0, warnings: 1, failed: 0, skipped: 0, total: 3 },
|
|
|
|
|
overallSeverity: 'warn',
|
|
|
|
|
results: [],
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openDoctor(page: Page): Promise<void> {
|
|
|
|
|
await page.goto('/ops/operations/doctor', { waitUntil: 'domcontentloaded' });
|
|
|
|
|
await expect(page.getByRole('heading', { name: /doctor diagnostics/i })).toBeVisible({
|
|
|
|
|
timeout: 15_000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function routeLiveUnifiedSearch(
|
|
|
|
|
page: Page,
|
|
|
|
|
capturedRequests?: Array<Record<string, unknown>>,
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
await page.route('**/api/v1/search/query', async (route) => {
|
|
|
|
|
const rawBody = route.request().postData() ?? '{}';
|
|
|
|
|
const parsedBody = safeParseRequest(rawBody);
|
|
|
|
|
if (capturedRequests) {
|
|
|
|
|
capturedRequests.push(parsedBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`${liveSearchBaseUrl}/v1/search/query`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'content-type': 'application/json',
|
|
|
|
|
'x-stellaops-scopes': liveScopes,
|
|
|
|
|
'x-stellaops-tenant': liveTenant,
|
|
|
|
|
'x-stellaops-actor': 'playwright-live',
|
|
|
|
|
},
|
|
|
|
|
body: rawBody,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const body = await response.text();
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
status: response.status,
|
|
|
|
|
contentType: response.headers.get('content-type') ?? 'application/json',
|
|
|
|
|
body,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function ensureLiveServiceHealthy(baseUrl: string): Promise<void> {
|
|
|
|
|
const response = await fetch(`${baseUrl}/health`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`Live AdvisoryAI health check failed with status ${response.status}.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function rebuildLiveIndexes(baseUrl: string): Promise<void> {
|
|
|
|
|
const headers = {
|
|
|
|
|
'content-type': 'application/json',
|
|
|
|
|
'x-stellaops-scopes': 'advisory-ai:admin',
|
|
|
|
|
'x-stellaops-tenant': liveTenant,
|
|
|
|
|
'x-stellaops-actor': 'playwright-live',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const knowledgeResponse = await fetch(`${baseUrl}/v1/advisory-ai/index/rebuild`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers,
|
|
|
|
|
});
|
|
|
|
|
if (!knowledgeResponse.ok) {
|
|
|
|
|
throw new Error(`Knowledge rebuild failed with status ${knowledgeResponse.status}.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const unifiedResponse = await fetch(`${baseUrl}/v1/search/index/rebuild`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers,
|
|
|
|
|
});
|
|
|
|
|
if (!unifiedResponse.ok) {
|
|
|
|
|
throw new Error(`Unified rebuild failed with status ${unifiedResponse.status}.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function safeParseRequest(rawBody: string): Record<string, unknown> {
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(rawBody) as Record<string, unknown>;
|
|
|
|
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
|
|
|
} catch {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|