mirror of
https://github.com/labring/FastGPT.git
synced 2026-02-27 01:02:22 +08:00
Sandbox move and vector test (#6381)
* remove sandbox * perf: vitest * doc
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
// Load vector database environment variables before tests run
|
||||
export default async function setup() {
|
||||
console.log('Vector DB integration tests - environment loaded');
|
||||
console.log('PG_URL configured:', Boolean(process.env.PG_URL));
|
||||
console.log('OCEANBASE_URL configured:', Boolean(process.env.OCEANBASE_URL));
|
||||
console.log('MILVUS_ADDRESS configured:', Boolean(process.env.MILVUS_ADDRESS));
|
||||
console.log('SEEKDB_URL configured:', Boolean(process.env.SEEKDB_URL));
|
||||
|
||||
return async () => {
|
||||
// Cleanup if needed
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
import { describe } from 'vitest';
|
||||
import { MilvusCtrl } from '@fastgpt/service/common/vectorDB/milvus';
|
||||
import { describe, vi } from 'vitest';
|
||||
import { createVectorDBTestSuite } from '../testSuites';
|
||||
|
||||
const isEnabled = Boolean(process.env.MILVUS_ADDRESS);
|
||||
const describePg = isEnabled ? describe : describe.skip;
|
||||
// Unmock vector controllers for integration tests
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/milvus');
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/constants');
|
||||
|
||||
describePg('Milvus Vector Integration', () => {
|
||||
import { MilvusCtrl } from '@fastgpt/service/common/vectorDB/milvus';
|
||||
|
||||
const isEnabled = Boolean(process.env.MILVUS_ADDRESS);
|
||||
|
||||
describe.skipIf(!isEnabled)('Milvus Vector Integration', () => {
|
||||
const vectorCtrl = new MilvusCtrl();
|
||||
createVectorDBTestSuite(vectorCtrl);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { describe } from 'vitest';
|
||||
import { ObVectorCtrl } from '@fastgpt/service/common/vectorDB/oceanbase';
|
||||
import { describe, vi } from 'vitest';
|
||||
import { createVectorDBTestSuite } from '../testSuites';
|
||||
|
||||
const isEnabled = Boolean(process.env.OCEANBASE_URL);
|
||||
const describePg = isEnabled ? describe : describe.skip;
|
||||
// Unmock vector controllers for integration tests
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/oceanbase');
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/constants');
|
||||
|
||||
describePg('Oceanbase Vector Integration', () => {
|
||||
import { ObVectorCtrl } from '@fastgpt/service/common/vectorDB/oceanbase';
|
||||
|
||||
const isEnabled = Boolean(process.env.OCEANBASE_URL);
|
||||
|
||||
describe.skipIf(!isEnabled)('Oceanbase Vector Integration', () => {
|
||||
const vectorCtrl = new ObVectorCtrl({ type: 'oceanbase' });
|
||||
createVectorDBTestSuite(vectorCtrl);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { describe } from 'vitest';
|
||||
import { PgVectorCtrl } from '@fastgpt/service/common/vectorDB/pg';
|
||||
import { describe, vi } from 'vitest';
|
||||
import { createVectorDBTestSuite } from '../testSuites';
|
||||
|
||||
const isEnabled = Boolean(process.env.PG_URL);
|
||||
const describePg = isEnabled ? describe : describe.skip;
|
||||
// Unmock vector controllers for integration tests
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/pg');
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/constants');
|
||||
|
||||
describePg('PG Vector Integration', () => {
|
||||
import { PgVectorCtrl } from '@fastgpt/service/common/vectorDB/pg';
|
||||
|
||||
const isEnabled = Boolean(process.env.PG_URL);
|
||||
|
||||
describe.skipIf(!isEnabled)('PG Vector Integration', () => {
|
||||
const vectorCtrl = new PgVectorCtrl();
|
||||
createVectorDBTestSuite(vectorCtrl);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { describe } from 'vitest';
|
||||
import { SeekVectorCtrl } from '@fastgpt/service/common/vectorDB/seekdb';
|
||||
import { describe, vi } from 'vitest';
|
||||
import { createVectorDBTestSuite } from '../testSuites';
|
||||
|
||||
const isEnabled = Boolean(process.env.SEEKDB_URL);
|
||||
const describePg = isEnabled ? describe : describe.skip;
|
||||
// Unmock vector controllers for integration tests
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/oceanbase');
|
||||
vi.unmock('@fastgpt/service/common/vectorDB/constants');
|
||||
|
||||
describePg('Seekdb Vector Integration', () => {
|
||||
import { SeekVectorCtrl } from '@fastgpt/service/common/vectorDB/seekdb';
|
||||
|
||||
const isEnabled = Boolean(process.env.SEEKDB_URL);
|
||||
|
||||
describe.skipIf(!isEnabled)('Seekdb Vector Integration', () => {
|
||||
const vectorCtrl = new SeekVectorCtrl({ type: 'seekdb' });
|
||||
createVectorDBTestSuite(vectorCtrl);
|
||||
});
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import { loadVectorDBEnv } from './utils';
|
||||
|
||||
// Load env before any modules that read process.env
|
||||
loadVectorDBEnv({ envFileNames: ['.env.test.local'] });
|
||||
@@ -1,23 +0,0 @@
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, '../../../projects/app/src'),
|
||||
'@fastgpt': resolve(__dirname, '../../../packages'),
|
||||
'@test': resolve(__dirname, '../..')
|
||||
}
|
||||
},
|
||||
test: {
|
||||
name: 'vectorDB',
|
||||
root: resolve(__dirname),
|
||||
setupFiles: './setup.ts',
|
||||
include: ['**/*.test.ts'],
|
||||
exclude: ['node_modules', 'dist'],
|
||||
testTimeout: 60000,
|
||||
hookTimeout: 60000,
|
||||
fileParallelism: false,
|
||||
reporters: ['verbose']
|
||||
}
|
||||
});
|
||||
@@ -8,9 +8,12 @@ import setupModels from './setupModels';
|
||||
import { clean } from './datas/users';
|
||||
import { connectionLogMongo, connectionMongo } from '@fastgpt/service/common/mongo';
|
||||
import { delay } from '@fastgpt/global/common/system/utils';
|
||||
import { loadVectorDBEnv } from './utils/env';
|
||||
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
|
||||
loadVectorDBEnv({ envFileNames: ['.env.test.local'] });
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.stubEnv('MONGODB_URI', inject('MONGODB_URI'));
|
||||
await connectMongo({ db: connectionMongo, url: inject('MONGODB_URI') });
|
||||
|
||||
@@ -26,7 +26,8 @@ const parseEnvFile = (filePath: string) => {
|
||||
|
||||
export const loadVectorDBEnv = (options: LoadVectorEnvOptions = {}) => {
|
||||
const envFileNames = options.envFileNames ?? ['.env.test.local'];
|
||||
const baseDir = resolve(__dirname);
|
||||
// __dirname is test/utils/, go up one level to test/
|
||||
const baseDir = resolve(__dirname, '..');
|
||||
|
||||
for (const envFileName of envFileNames) {
|
||||
const filePath = resolve(baseDir, envFileName);
|
||||
Reference in New Issue
Block a user