[Obs AI Assistant] Minor improvements to KB API tests (#207198)

Minor improvements to the API tests
This commit is contained in:
Søren Louv-Jansen 2025-01-20 23:32:22 +01:00 committed by GitHub
parent 583b852251
commit 35fe7221a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 18 deletions

View file

@ -67,8 +67,9 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
// Failing: See https://github.com/elastic/kibana/issues/206474
describe.skip('When there are knowledge base entries (from 8.15 or earlier) that does not contain semantic_text embeddings', function () {
// security_exception: action [indices:admin/settings/update] is unauthorized for user [testing-internal] with effective roles [superuser] on restricted indices [.kibana_security_solution_1,.kibana_task_manager_1,.kibana_alerting_cases_1,.kibana_usage_counters_1,.kibana_1,.kibana_ingest_1,.kibana_analytics_1], this action is granted by the index privileges [manage,all]
this.tags(['failsOnMKI']);
// Intentionally skipped on MKI because es_archiver.load is not allowed there, and because the migration scenario being tested is not relevant to MKI.
// https://github.com/elastic/obs-ai-assistant-team/issues/195
this.tags(['skipMKI']);
before(async () => {
await clearKnowledgeBase(es);

View file

@ -69,18 +69,17 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
isPublic: false,
},
{
username: 'secondary_editor' as const,
username: 'admin' as const,
isPublic: true,
},
{
username: 'secondary_editor' as const,
username: 'admin' as const,
isPublic: false,
},
].map(async ({ username, isPublic }) => {
const visibility = isPublic ? 'Public' : 'Private';
const user = username === 'editor' ? 'editor' : 'admin';
const { status } = await observabilityAIAssistantAPIClient[user]({
const { status } = await observabilityAIAssistantAPIClient[username]({
endpoint: 'PUT /internal/observability_ai_assistant/kb/user_instructions',
params: {
body: {
@ -95,6 +94,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
await Promise.all(promises);
});
it('"editor" can retrieve their own private instructions and the public instruction', async () => {
await retry.try(async () => {
const res = await observabilityAIAssistantAPIClient.editor({
@ -119,9 +119,9 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
text: 'Public user instruction from "editor"',
},
{
id: 'public-doc-from-secondary_editor',
id: 'public-doc-from-admin',
public: true,
text: 'Public user instruction from "secondary_editor"',
text: 'Public user instruction from "admin"',
},
])
);
@ -147,14 +147,14 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
text: 'Public user instruction from "editor"',
},
{
id: 'public-doc-from-secondary_editor',
id: 'public-doc-from-admin',
public: true,
text: 'Public user instruction from "secondary_editor"',
text: 'Public user instruction from "admin"',
},
{
id: 'private-doc-from-secondary_editor',
id: 'private-doc-from-admin',
public: false,
text: 'Private user instruction from "secondary_editor"',
text: 'Private user instruction from "admin"',
},
])
);
@ -213,9 +213,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const userInstructionText =
'Be polite and use language that is easy to understand. Never disagree with the user.';
async function getConversationForUser(username: string) {
const user = username === 'editor' ? 'editor' : 'admin';
async function getConversationForUser(username: 'editor' | 'admin') {
// the user instruction is always created by "editor" user
const { status } = await observabilityAIAssistantAPIClient.editor({
endpoint: 'PUT /internal/observability_ai_assistant/kb/user_instructions',
@ -251,7 +249,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
},
];
const createResponse = await observabilityAIAssistantAPIClient[user]({
const createResponse = await observabilityAIAssistantAPIClient[username]({
endpoint: 'POST /internal/observability_ai_assistant/chat/complete',
params: {
body: {
@ -269,7 +267,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const conversationCreatedEvent = getConversationCreatedEvent(createResponse.body);
const conversationId = conversationCreatedEvent.conversation.id;
const res = await observabilityAIAssistantAPIClient[user]({
const res = await observabilityAIAssistantAPIClient[username]({
endpoint: 'GET /internal/observability_ai_assistant/conversation/{conversationId}',
params: {
path: {
@ -323,7 +321,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});
it('does not add the instruction conversation for other users', async () => {
const conversation = await getConversationForUser('secondary_editor');
const conversation = await getConversationForUser('admin');
const systemMessage = conversation.messages.find(
(message) => message.message.role === MessageRole.System
)!;