Skip to content

Commit

Permalink
[8.16] [Security assistant] Update conversations api improvement (ela…
Browse files Browse the repository at this point in the history
…stic#206828) (elastic#206865)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Security assistant] Update conversations api improvement
(elastic#206828)](elastic#206828)

<!--- Backport version: 9.6.4 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-15T20:36:33Z","message":"[Security
assistant] Update conversations api improvement
(elastic#206828)","sha":"56ce5d45c02436fc2cc31b20f1ccf29823bacf59","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:all-open","Team:Security
Generative AI"],"title":"[Security assistant] Update conversations api
improvement","number":206828,"url":"https://github.com/elastic/kibana/pull/206828","mergeCommit":{"message":"[Security
assistant] Update conversations api improvement
(elastic#206828)","sha":"56ce5d45c02436fc2cc31b20f1ccf29823bacf59"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206828","number":206828,"mergeCommit":{"message":"[Security
assistant] Update conversations api improvement
(elastic#206828)","sha":"56ce5d45c02436fc2cc31b20f1ccf29823bacf59"}},{"url":"https://github.com/elastic/kibana/pull/206861","number":206861,"branch":"8.17","state":"OPEN"},{"url":"https://github.com/elastic/kibana/pull/206862","number":206862,"branch":"8.x","state":"OPEN"}]}]
BACKPORT-->
  • Loading branch information
stephmilovic authored Jan 16, 2025
1 parent 6f20630 commit 00ffc91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../__mocks__/conversations_schema.mock';
import { updateConversationRoute } from './update_route';
import { AuthenticatedUser } from '@kbn/core-security-common';
import expect from 'expect';

describe('Update conversation route', () => {
let server: ReturnType<typeof serverMock.create>;
Expand All @@ -28,6 +29,7 @@ describe('Update conversation route', () => {
} as AuthenticatedUser;

beforeEach(() => {
jest.clearAllMocks();
server = serverMock.create();
({ clients, context } = requestContextMock.createTools());

Expand Down Expand Up @@ -151,5 +153,27 @@ describe('Update conversation route', () => {
`messages.0.role: Invalid enum value. Expected 'system' | 'user' | 'assistant', received 'invalid'`
);
});

// validate id is correct, check happens on L71 in update_route.ts
test('validates id is correct', async () => {
const request = requestMock.create({
method: 'put',
path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID,
body: {
...getUpdateConversationSchemaMock(),
id: 'invalid-id',
},
params: { id: 'real-id' },
});
await server.inject(request, requestContextMock.convertContext(context));

expect(
clients.elasticAssistant.getAIAssistantConversationsDataClient.updateConversation
).toHaveBeenCalledWith(
expect.objectContaining({
conversationUpdateProps: expect.objectContaining({ id: 'real-id' }),
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const updateConversationRoute = (router: ElasticAssistantPluginRouter) =>
});
}
const conversation = await dataClient?.updateConversation({
conversationUpdateProps: request.body,
conversationUpdateProps: { ...request.body, id },
});
if (conversation == null) {
return assistantResponse.error({
Expand Down

0 comments on commit 00ffc91

Please sign in to comment.