Compare commits

...

2 Commits

Author SHA1 Message Date
gru-agent[bot]
bdd184231d Add unit tests for processChatTimeFilter function in chat utils 2025-06-03 08:43:37 +00:00
dependabot[bot]
b974574157 chore(deps): bump tar-fs in /plugins/webcrawler/SPIDER (#4945)
Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.0.8 to 3.0.9.
- [Commits](https://github.com/mafintosh/tar-fs/compare/v3.0.8...v3.0.9)

---
updated-dependencies:
- dependency-name: tar-fs
  dependency-version: 3.0.9
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-03 16:02:05 +08:00
2 changed files with 132 additions and 3 deletions

View File

@@ -4992,9 +4992,10 @@
}
},
"node_modules/tar-fs": {
"version": "3.0.8",
"resolved": "https://registry.npmmirror.com/tar-fs/-/tar-fs-3.0.8.tgz",
"integrity": "sha512-ZoROL70jptorGAlgAYiLoBLItEKw/fUxg9BSYK/dF/GAGYFJOJJJMvjPAKDJraCXFwadD456FCuvLWgfhMsPwg==",
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.9.tgz",
"integrity": "sha512-XF4w9Xp+ZQgifKakjZYmFdkLoSWd34VGKcsTCwlNWM7QG3ZbaxnTsaBwnjFZqHRf/rROxaR8rXnbtwdvaDI+lA==",
"license": "MIT",
"dependencies": {
"pump": "^3.0.0",
"tar-stream": "^3.1.5"

View File

@@ -0,0 +1,128 @@
import { describe, it, expect } from 'vitest';
import { processChatTimeFilter } from '@/service/core/chat/utils';
import type { DatasetCiteItemType } from '@fastgpt/global/core/dataset/type';
describe('processChatTimeFilter', () => {
const baseTime = new Date('2025-01-01');
it('should return original item if no history', () => {
const item: DatasetCiteItemType = {
id: '1',
q: 'original q',
a: 'original a',
updateTime: baseTime.getTime(),
history: undefined
};
const result = processChatTimeFilter([item], baseTime);
expect(result).toEqual([item]);
});
it('should return original item if updateTime <= chatTime', () => {
const item: DatasetCiteItemType = {
id: '1',
q: 'original q',
a: 'original a',
updateTime: baseTime.getTime() - 1000,
history: [
{
q: 'history q',
a: 'history a',
updateTime: baseTime.getTime() - 2000
}
]
};
const result = processChatTimeFilter([item], baseTime);
expect(result).toEqual([item]);
});
it('should return history item if one exists before chatTime', () => {
const item: DatasetCiteItemType = {
id: '1',
q: 'original q',
a: 'original a',
updateTime: baseTime.getTime() + 2000,
history: [
{
q: 'history q',
a: 'history a',
updateTime: baseTime.getTime() - 1000
}
]
};
const result = processChatTimeFilter([item], baseTime);
expect(result).toEqual([
{
...item,
q: 'history q',
a: 'history a',
updateTime: baseTime.getTime() - 1000,
updated: true
}
]);
});
it('should return original item if no history before chatTime', () => {
const item: DatasetCiteItemType = {
id: '1',
q: 'original q',
a: 'original a',
updateTime: baseTime.getTime() + 2000,
history: [
{
q: 'history q',
a: 'history a',
updateTime: baseTime.getTime() + 1000
}
]
};
const result = processChatTimeFilter([item], baseTime);
expect(result).toEqual([item]);
});
it('should handle multiple items', () => {
const items: DatasetCiteItemType[] = [
{
id: '1',
q: 'original q1',
a: 'original a1',
updateTime: baseTime.getTime() + 2000,
history: [
{
q: 'history q1',
a: 'history a1',
updateTime: baseTime.getTime() - 1000
}
]
},
{
id: '2',
q: 'original q2',
a: 'original a2',
updateTime: baseTime.getTime() - 1000,
history: [
{
q: 'history q2',
a: 'history a2',
updateTime: baseTime.getTime() - 2000
}
]
}
];
const result = processChatTimeFilter(items, baseTime);
expect(result).toEqual([
{
...items[0],
q: 'history q1',
a: 'history a1',
updateTime: baseTime.getTime() - 1000,
updated: true
},
items[1]
]);
});
});