mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
fix: use correct user id in forked session (#7710)
This commit is contained in:
@@ -571,6 +571,7 @@ export class ChatSessionService {
|
|||||||
|
|
||||||
const forkedState = {
|
const forkedState = {
|
||||||
...state,
|
...state,
|
||||||
|
userId: options.userId,
|
||||||
sessionId: randomUUID(),
|
sessionId: randomUUID(),
|
||||||
messages: [],
|
messages: [],
|
||||||
parentSessionId: options.sessionId,
|
parentSessionId: options.sessionId,
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ test('should be able to manage chat session', async t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should be able to fork 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', [
|
await prompt.set('prompt', 'model', [
|
||||||
{ role: 'system', content: 'hello {{word}}' },
|
{ role: 'system', content: 'hello {{word}}' },
|
||||||
@@ -305,8 +305,10 @@ test('should be able to fork chat session', async t => {
|
|||||||
...commonParams,
|
...commonParams,
|
||||||
});
|
});
|
||||||
t.not(sessionId, forkedSessionId1, 'should fork a new session');
|
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({
|
const forkedSessionId2 = await session.fork({
|
||||||
userId,
|
userId: newUser.id,
|
||||||
sessionId,
|
sessionId,
|
||||||
latestMessageId,
|
latestMessageId,
|
||||||
...commonParams,
|
...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))!;
|
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
|
const finalMessages = s2
|
||||||
.finish(params) // @ts-expect-error
|
.finish(params) // @ts-expect-error
|
||||||
.map(({ id: _, createdAt: __, ...m }) => m);
|
.map(({ id: _, createdAt: __, ...m }) => m);
|
||||||
|
|||||||
Reference in New Issue
Block a user