feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BaseEnum, SpaceAppEnum } from '../../src/const/app';
describe('const/app', () => {
describe('BaseEnum', () => {
test('should have correct values for all enum members', () => {
expect(BaseEnum.Home).toBe('home');
expect(BaseEnum.Explore).toBe('explore');
expect(BaseEnum.Store).toBe('store');
expect(BaseEnum.Model).toBe('model');
expect(BaseEnum.Space).toBe('space');
expect(BaseEnum.Workflow).toBe('work_flow');
expect(BaseEnum.Invite).toBe('invite');
expect(BaseEnum.Token).toBe('token');
expect(BaseEnum.Open).toBe('open');
expect(BaseEnum.PluginMockSet).toBe('plugin_mock_set');
expect(BaseEnum.Search).toBe('search');
expect(BaseEnum.Premium).toBe('premium');
expect(BaseEnum.User).toBe('user');
});
test('should have the expected number of enum values', () => {
const enumValues = Object.values(BaseEnum);
expect(enumValues.length).toBe(14);
});
});
describe('SpaceAppEnum', () => {
test('should have correct values for all enum members', () => {
expect(SpaceAppEnum.BOT).toBe('bot');
expect(SpaceAppEnum.DEVELOP).toBe('develop');
expect(SpaceAppEnum.LIBRARY).toBe('library');
expect(SpaceAppEnum.PLUGIN).toBe('plugin');
expect(SpaceAppEnum.WORKFLOW).toBe('workflow');
expect(SpaceAppEnum.KNOWLEDGE).toBe('knowledge');
expect(SpaceAppEnum.TEAM).toBe('team');
expect(SpaceAppEnum.PERSONAL).toBe('personal');
expect(SpaceAppEnum.WIDGET).toBe('widget');
expect(SpaceAppEnum.EVALUATION).toBe('evaluation');
expect(SpaceAppEnum.SOCIAL_SCENE).toBe('social-scene');
expect(SpaceAppEnum.IMAGEFLOW).toBe('imageflow');
});
test('should have the expected number of enum values', () => {
const enumValues = Object.values(SpaceAppEnum);
expect(enumValues.length).toBe(19);
});
});
});

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { uniqueId } from 'lodash-es';
import {
defaultConversationKey,
defaultConversationUniqId,
} from '../../src/const/community';
// 模拟 lodash-es 的 uniqueId 函数
vi.mock('lodash-es', () => ({
uniqueId: vi.fn().mockReturnValue('mocked-unique-id'),
}));
describe('const/community', () => {
test('defaultConversationKey should be -1', () => {
expect(defaultConversationKey).toBe(-1);
});
test('defaultConversationUniqId should be a unique ID generated by lodash-es', () => {
// 验证 uniqueId 函数被调用
expect(uniqueId).toHaveBeenCalled();
// 验证 defaultConversationUniqId 的值是由模拟的 uniqueId 函数返回的
expect(defaultConversationUniqId).toBe('mocked-unique-id');
});
});

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { COZE_TOKEN_INSUFFICIENT_ERROR_CODE } from '../../src/const/custom';
describe('const/custom', () => {
describe('COZE_TOKEN_INSUFFICIENT_ERROR_CODE', () => {
test('should be an array', () => {
expect(Array.isArray(COZE_TOKEN_INSUFFICIENT_ERROR_CODE)).toBe(true);
});
test('should contain exactly 2 error codes', () => {
expect(COZE_TOKEN_INSUFFICIENT_ERROR_CODE.length).toBe(2);
});
test('should contain the BOT error code', () => {
expect(COZE_TOKEN_INSUFFICIENT_ERROR_CODE).toContain('702082020');
});
test('should contain the WORKFLOW error code', () => {
expect(COZE_TOKEN_INSUFFICIENT_ERROR_CODE).toContain('702095072');
});
// 移除失败的测试用例
// 原因:在 JavaScript 中,即使使用 const 声明数组,其内容仍然是可变的
// 只有数组引用是不可变的,而不是数组内容
});
});