mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 20:16:26 +08:00
feat(core): support fork session without latestMessageId (#12587)
Close [AI-86](https://linear.app/affine-design/issue/AI-86) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved chat session forking to allow creating a fork without specifying the latest message, enabling more flexible session management. - **Bug Fixes** - Forking a chat session with an invalid latest message ID now correctly returns an error. - **Tests** - Added and updated test cases to cover session forking with missing or invalid latest message IDs, ensuring robust behavior in these scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -410,6 +410,27 @@ test('should be able to fork chat session', async t => {
|
||||
'should fork new session with same params'
|
||||
);
|
||||
|
||||
// fork session without latestMessageId
|
||||
const forkedSessionId3 = await session.fork({
|
||||
userId,
|
||||
sessionId,
|
||||
...commonParams,
|
||||
});
|
||||
|
||||
// fork session with wrong latestMessageId
|
||||
await t.throwsAsync(
|
||||
session.fork({
|
||||
userId,
|
||||
sessionId,
|
||||
latestMessageId: 'wrong-message-id',
|
||||
...commonParams,
|
||||
}),
|
||||
{
|
||||
instanceOf: Error,
|
||||
},
|
||||
'should not able to fork new session with wrong latestMessageId'
|
||||
);
|
||||
|
||||
const cleanObject = (obj: any[]) =>
|
||||
JSON.parse(
|
||||
JSON.stringify(obj, (k, v) =>
|
||||
@@ -436,11 +457,17 @@ test('should be able to fork chat session', async t => {
|
||||
t.snapshot(cleanObject(finalMessages), 'should generate the final message');
|
||||
}
|
||||
|
||||
// check third times forked session
|
||||
{
|
||||
const s3 = (await session.get(forkedSessionId3))!;
|
||||
const finalMessages = s3.finish(params);
|
||||
t.snapshot(cleanObject(finalMessages), 'should generate the final message');
|
||||
}
|
||||
|
||||
// check original session messages
|
||||
{
|
||||
const s3 = (await session.get(sessionId))!;
|
||||
|
||||
const finalMessages = s3.finish(params);
|
||||
const s4 = (await session.get(sessionId))!;
|
||||
const finalMessages = s4.finish(params);
|
||||
t.snapshot(cleanObject(finalMessages), 'should generate the final message');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user