fix: value type (#6076)

* fix: value type

* perf: empty val check
This commit is contained in:
Archer
2025-12-10 22:23:40 +08:00
committed by GitHub
parent 2da73a6555
commit eaeabf825a
6 changed files with 21 additions and 133 deletions
@@ -19,6 +19,8 @@ describe('replaceJsonBodyString', () => {
] as unknown as RuntimeNodeItemType[];
const mockVariables = {
undefinedVar: undefined,
nullVar: null,
userName: 'John Doe',
userAge: 30,
isActive: true,
@@ -43,6 +45,14 @@ describe('replaceJsonBodyString', () => {
};
describe('Basic variable replacement functionality', () => {
it('字符串为空', () => {
const input = '{"name": "{{undefinedVar}}"}';
const expected = '{"name": ""}';
const result = replaceJsonBodyString({ text: input }, mockProps);
expect(result).toBe(expected);
});
it('should correctly replace string variables', () => {
const input = '{"name": "{{userName}}", "greeting": "Hello {{userName}}"}';
const expected = '{"name": "John Doe", "greeting": "Hello John Doe"}';
@@ -241,7 +251,7 @@ describe('replaceJsonBodyString', () => {
it('should handle non-existent variables', () => {
const input = '{"missing": "{{nonExistentVar}}", "static": "value"}';
const expected = '{"missing": "null", "static": "value"}';
const expected = '{"missing": "", "static": "value"}';
const result = replaceJsonBodyString({ text: input }, mockProps);
expect(result).toBe(expected);
@@ -626,7 +636,7 @@ describe('replaceJsonBodyString', () => {
// Verify no code execution occurred (template injection variable was replaced with null because it doesn't exist)
expect(typeof parsed.templateTests.inject).toBe('string');
expect(parsed.templateTests.inject).toBe('null'); // Non-existent variables become "null"
expect(parsed.templateTests.inject).toBe(''); // Non-existent variables become "null"
});
});
});
@@ -311,109 +311,3 @@ describe('valueTypeFormat', () => {
// });
// });
});
import { getHistories } from '@fastgpt/service/core/workflow/dispatch/utils';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
describe('getHistories test', async () => {
const MockHistories: ChatItemType[] = [
{
obj: ChatRoleEnum.System,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好'
}
}
]
},
{
obj: ChatRoleEnum.Human,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好'
}
}
]
},
{
obj: ChatRoleEnum.AI,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好2'
}
}
]
},
{
obj: ChatRoleEnum.Human,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好3'
}
}
]
},
{
obj: ChatRoleEnum.AI,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好4'
}
}
]
}
];
it('getHistories', async () => {
// Number
expect(getHistories(1, MockHistories)).toEqual([
...MockHistories.slice(0, 1),
...MockHistories.slice(-2)
]);
expect(getHistories(2, MockHistories)).toEqual([...MockHistories.slice(0)]);
expect(getHistories(4, MockHistories)).toEqual([...MockHistories.slice(0)]);
// Array
expect(
getHistories(
[
{
obj: ChatRoleEnum.Human,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好'
}
}
]
}
],
MockHistories
)
).toEqual([
{
obj: ChatRoleEnum.Human,
value: [
{
type: ChatItemValueTypeEnum.text,
text: {
content: '你好'
}
}
]
}
]);
});
});