Files
FastGPT/test/mocks/common/vector.ts
T
Ryo 289da0f7b0 chore: bump pro submodule for hydration stability (#6808)
* sandbox-sync-agent

* refactor: host pro as submodule

* chore: checkpoint host pro restructure

* refactor workspace test layout and startup init

* chore: update next turbopack setup

* chore: snapshot current work before actions fix

* chore: update pro submodule

* chore: point pro submodule url to upstream https

* fix: Dockerfile

* chore: update pro submodule

* ci: support private pro submodule token and skip fork jobs

* fix(ci): build sdk workspace deps before code-sandbox bundle

* fix(app): exclude vitest configs from production typecheck

* fix(app-image): build sdk packages before next build

* fix(ci): align dockerfiles with workspace sdk build flow

* chore(docker): upgrade node20 docker images to node24

* fix(ci): read admin coverage output path in pro test workflow

* fix(app-image): include next-i18next config and locale assets

* chore: update pro submodule

* chore: do not specify branch for submodule

* chore: remove most ts-nocheck sign

* chore: update pro submodule

* chore: remove sandbox-agent-sync package

* chore: do not modify "pushData" file logic

* fix: health check

* chore: restore dev axios proxy state

* fix: test-fastgpt report workflow

* fix: use valid vitest coverage action inputs
2026-04-27 17:44:12 +08:00

80 lines
2.2 KiB
TypeScript

import { SEEKDB_ADDRESS } from '@fastgpt/service/common/vectorDB/constants';
import { vi } from 'vitest';
/**
* Mock Vector Controller for testing
*/
export const mockVectorInsert = vi.fn().mockResolvedValue({
insertIds: ['id_1', 'id_2', 'id_3']
});
export const mockVectorDelete = vi.fn().mockResolvedValue(undefined);
export const mockVectorEmbRecall = vi.fn().mockResolvedValue({
results: [
{ id: '1', collectionId: 'col_1', score: 0.95 },
{ id: '2', collectionId: 'col_2', score: 0.85 }
]
});
export const mockVectorInit = vi.fn().mockResolvedValue(undefined);
export const mockGetVectorDataByTime = vi.fn().mockResolvedValue([
{ id: '1', teamId: 'team_1', datasetId: 'dataset_1' },
{ id: '2', teamId: 'team_1', datasetId: 'dataset_2' }
]);
export const mockGetVectorCountByTeamId = vi.fn().mockResolvedValue(100);
export const mockGetVectorCount = vi.fn().mockResolvedValue(50);
const MockVectorCtrl = vi.fn().mockImplementation(function () {
return {
init: mockVectorInit,
insert: mockVectorInsert,
delete: mockVectorDelete,
embRecall: mockVectorEmbRecall,
getVectorDataByTime: mockGetVectorDataByTime,
getVectorCountByTeamId: mockGetVectorCountByTeamId,
getVectorCount: mockGetVectorCount
};
});
// Mock PgVectorCtrl
vi.mock('@fastgpt/service/common/vectorDB/pg', () => ({
PgVectorCtrl: MockVectorCtrl
}));
// Mock ObVectorCtrl
vi.mock('@fastgpt/service/common/vectorDB/oceanbase', () => ({
ObVectorCtrl: MockVectorCtrl
}));
// Mock MilvusCtrl
vi.mock('@fastgpt/service/common/vectorDB/milvus', () => ({
MilvusCtrl: MockVectorCtrl
}));
// Mock constants - use PG_ADDRESS to ensure PgVectorCtrl is used
vi.mock('@fastgpt/service/common/vectorDB/constants', () => ({
DatasetVectorDbName: 'fastgpt',
DatasetVectorTableName: 'modeldata',
PG_ADDRESS: 'mock://pg',
OCEANBASE_ADDRESS: undefined,
MILVUS_ADDRESS: undefined,
MILVUS_TOKEN: undefined,
SEEKDB_ADDRESS: undefined
}));
// Export mocks for test assertions
export const resetVectorMocks = () => {
mockVectorInsert.mockClear();
mockVectorDelete.mockClear();
mockVectorEmbRecall.mockClear();
mockVectorInit.mockClear();
mockGetVectorDataByTime.mockClear();
mockGetVectorCountByTeamId.mockClear();
mockGetVectorCount.mockClear();
};