mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
fix(server): copilot test condition (#11417)
This commit is contained in:
@@ -2,7 +2,7 @@ import type { ExecutionContext, TestFn } from 'ava';
|
|||||||
import ava from 'ava';
|
import ava from 'ava';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { ConfigModule } from '../base/config';
|
import { ServerFeature, ServerService } from '../core';
|
||||||
import { AuthService } from '../core/auth';
|
import { AuthService } from '../core/auth';
|
||||||
import { QuotaModule } from '../core/quota';
|
import { QuotaModule } from '../core/quota';
|
||||||
import { CopilotModule } from '../plugins/copilot';
|
import { CopilotModule } from '../plugins/copilot';
|
||||||
@@ -36,13 +36,7 @@ type Tester = {
|
|||||||
};
|
};
|
||||||
const test = ava as TestFn<Tester>;
|
const test = ava as TestFn<Tester>;
|
||||||
|
|
||||||
const isCopilotConfigured =
|
let isCopilotConfigured = false;
|
||||||
!!process.env.COPILOT_OPENAI_API_KEY &&
|
|
||||||
!!process.env.COPILOT_FAL_API_KEY &&
|
|
||||||
!!process.env.COPILOT_PERPLEXITY_API_KEY &&
|
|
||||||
process.env.COPILOT_OPENAI_API_KEY !== '1' &&
|
|
||||||
process.env.COPILOT_FAL_API_KEY !== '1' &&
|
|
||||||
process.env.COPILOT_PERPLEXITY_API_KEY !== '1';
|
|
||||||
const runIfCopilotConfigured = test.macro(
|
const runIfCopilotConfigured = test.macro(
|
||||||
async (
|
async (
|
||||||
t,
|
t,
|
||||||
@@ -59,30 +53,12 @@ const runIfCopilotConfigured = test.macro(
|
|||||||
|
|
||||||
test.serial.before(async t => {
|
test.serial.before(async t => {
|
||||||
const module = await createTestingModule({
|
const module = await createTestingModule({
|
||||||
imports: [
|
imports: [QuotaModule, CopilotModule],
|
||||||
ConfigModule.override({
|
|
||||||
copilot: {
|
|
||||||
providers: {
|
|
||||||
openai: {
|
|
||||||
apiKey: process.env.COPILOT_OPENAI_API_KEY || '',
|
|
||||||
},
|
|
||||||
fal: {
|
|
||||||
apiKey: process.env.COPILOT_FAL_API_KEY || '',
|
|
||||||
},
|
|
||||||
perplexity: {
|
|
||||||
apiKey: process.env.COPILOT_PERPLEXITY_API_KEY || '',
|
|
||||||
},
|
|
||||||
gemini: {
|
|
||||||
apiKey: process.env.COPILOT_GOOGLE_API_KEY || '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
QuotaModule,
|
|
||||||
CopilotModule,
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const service = module.get(ServerService);
|
||||||
|
isCopilotConfigured = service.features.includes(ServerFeature.Copilot);
|
||||||
|
|
||||||
const auth = module.get(AuthService);
|
const auth = module.get(AuthService);
|
||||||
const prompt = module.get(PromptService);
|
const prompt = module.get(PromptService);
|
||||||
const factory = module.get(CopilotProviderFactory);
|
const factory = module.get(CopilotProviderFactory);
|
||||||
@@ -357,10 +333,10 @@ const actions = [
|
|||||||
.trim();
|
.trim();
|
||||||
t.notThrows(() => {
|
t.notThrows(() => {
|
||||||
z.object({
|
z.object({
|
||||||
speaker: z.string(),
|
a: z.string(),
|
||||||
start: z.string(),
|
s: z.number(),
|
||||||
end: z.string(),
|
e: z.number(),
|
||||||
transcription: z.string(),
|
t: z.string(),
|
||||||
})
|
})
|
||||||
.array()
|
.array()
|
||||||
.parse(JSON.parse(cleaned));
|
.parse(JSON.parse(cleaned));
|
||||||
|
|||||||
Reference in New Issue
Block a user