Skip to content

Commit

Permalink
Fix functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Nov 6, 2024
1 parent 3114e7d commit 094f94c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const functionSummariseRoute = createObservabilityAIAssistantServerRoute({
endpoint: 'POST /internal/observability_ai_assistant/functions/summarize',
params: t.type({
body: t.type({
title: t.string,
text: nonEmptyStringRt,
confidence: t.union([t.literal('low'), t.literal('medium'), t.literal('high')]),
is_correction: toBooleanRt,
Expand All @@ -142,6 +143,7 @@ const functionSummariseRoute = createObservabilityAIAssistantServerRoute({
}

const {
title,
confidence,
is_correction: isCorrection,
text,
Expand All @@ -151,6 +153,7 @@ const functionSummariseRoute = createObservabilityAIAssistantServerRoute({

return client.addKnowledgeBaseEntry({
entry: {
title,
confidence,
id: v4(),
is_correction: isCorrection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import expect from '@kbn/expect';
import { subj as testSubjSelector } from '@kbn/test-subj-selector';
import {
clearKnowledgeBase,
createKnowledgeBaseModel,
deleteKnowledgeBaseModel,
} from '../../../observability_ai_assistant_api_integration/tests/knowledge_base/helpers';
Expand All @@ -20,6 +21,7 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte
const testSubjects = getService('testSubjects');
const log = getService('log');
const ml = getService('ml');
const es = getService('es');
const { common } = getPageObjects(['common']);

async function saveKbEntry({
Expand All @@ -33,6 +35,7 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte
endpoint: 'POST /internal/observability_ai_assistant/functions/summarize',
params: {
body: {
title: 'Favourite color',
text,
confidence: 'high',
is_correction: false,
Expand All @@ -45,6 +48,8 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte

describe('Knowledge management tab', () => {
before(async () => {
await clearKnowledgeBase(es);

// create a knowledge base model
await createKnowledgeBaseModel(ml);

Expand All @@ -60,7 +65,7 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte
});

after(async () => {
await Promise.all([deleteKnowledgeBaseModel(ml), ui.auth.logout()]);
await Promise.all([deleteKnowledgeBaseModel(ml), clearKnowledgeBase(es), ui.auth.logout()]);
});

describe('when the LLM calls the "summarize" function for two different users', () => {
Expand All @@ -75,22 +80,22 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte

const rows = await Promise.all(
entryTitleCells.map(async (cell) => {
const entryTitleText = await cell.getVisibleText();
const title = await cell.getVisibleText();
const parentRow = await cell.findByXpath('ancestor::tr');

const author = await parentRow.findByCssSelector(
const authorElm = await parentRow.findByCssSelector(
testSubjSelector(ui.pages.kbManagementTab.tableAuthorCell)
);
const authorText = await author.getVisibleText();
const author = await authorElm.getVisibleText();
const rowText = (await parentRow.getVisibleText()).split('\n');

return { rowText, authorText, entryTitleText };
return { rowText, author, title };
})
);

log.debug(`Found ${rows.length} rows in the KB management table: ${JSON.stringify(rows)}`);

return rows.filter(({ entryTitleText }) => entryTitleText === 'my_fav_color');
return rows.filter(({ title }) => title === 'Favourite color');
}

before(async () => {
Expand All @@ -112,7 +117,7 @@ export default function ApiTest({ getService, getPageObjects }: FtrProviderConte

it('shows two different authors', async () => {
const entries = await getKnowledgeBaseEntries();
expect(entries.map(({ authorText }) => authorText)).to.eql(['secondary_editor', 'editor']);
expect(entries.map(({ author }) => author)).to.eql(['secondary_editor', 'editor']);
});
});
});
Expand Down

0 comments on commit 094f94c

Please sign in to comment.