fix: use correct user id in forked session (#7710)

This commit is contained in:
darkskygit
2024-08-05 09:03:11 +00:00
parent 5050418c1a
commit 73a6723d15
2 changed files with 9 additions and 3 deletions

View File

@@ -571,6 +571,7 @@ export class ChatSessionService {
const forkedState = {
...state,
userId: options.userId,
sessionId: randomUUID(),
messages: [],
parentSessionId: options.sessionId,

View File

@@ -273,7 +273,7 @@ test('should be able to manage chat session', async t => {
});
test('should be able to fork chat session', async t => {
const { prompt, session } = t.context;
const { auth, prompt, session } = t.context;
await prompt.set('prompt', 'model', [
{ role: 'system', content: 'hello {{word}}' },
@@ -305,8 +305,10 @@ test('should be able to fork chat session', async t => {
...commonParams,
});
t.not(sessionId, forkedSessionId1, 'should fork a new session');
const newUser = await auth.signUp('test', 'darksky.1@affine.pro', '123456');
const forkedSessionId2 = await session.fork({
userId,
userId: newUser.id,
sessionId,
latestMessageId,
...commonParams,
@@ -335,10 +337,13 @@ test('should be able to fork chat session', async t => {
);
}
// check second times forked session messages
// check second times forked session
{
const s2 = (await session.get(forkedSessionId2))!;
// should overwrite user id
t.is(s2.config.userId, newUser.id, 'should have same user id');
const finalMessages = s2
.finish(params) // @ts-expect-error
.map(({ id: _, createdAt: __, ...m }) => m);