Files
openmaic/OpenMAIC/tests/lib/makelore-runtime/health.test.ts

75 lines
2.3 KiB
TypeScript

import { mkdtemp, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it, vi } from 'vitest';
const DIRECTORY_ENV = [
'CLASSROOM_DATA_DIR',
'CLASSROOM_JOBS_DIR',
'COURSE_FRAMEWORK_DIR',
'COURSE_MANIFEST_DIR',
'COURSEWARE_DATA_DIR',
'COURSEWARE_BUNDLE_DIR',
'LEARNING_COURSE_PACKAGE_DIR',
'LEARNING_COURSE_STORE_DIR',
] as const;
const TTS_ENV = [
'TTS_OPENAI_API_KEY',
'TTS_AZURE_API_KEY',
'TTS_GLM_API_KEY',
'TTS_QWEN_API_KEY',
'TTS_VOXCPM_API_KEY',
'TTS_DOUBAO_API_KEY',
'TTS_ELEVENLABS_API_KEY',
'TTS_MINIMAX_API_KEY',
'TTS_LEMONADE_BASE_URL',
] as const;
const temporaryRoots: string[] = [];
afterEach(async () => {
vi.unstubAllEnvs();
vi.resetModules();
await Promise.all(temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
});
async function configureEngine() {
const root = await mkdtemp(path.join(os.tmpdir(), 'openmaic-learning-health-'));
temporaryRoots.push(root);
vi.stubEnv('NODE_ENV', 'production');
vi.stubEnv('OPENMAIC_DEPLOYMENT_ROLE', 'server');
vi.stubEnv('LEARNING_ENGINE_TOKEN', 'test-runtime-token');
vi.stubEnv('OPENAI_API_KEY', 'test-llm-key');
DIRECTORY_ENV.forEach((name) => vi.stubEnv(name, path.join(root, name.toLowerCase())));
TTS_ENV.forEach((name) => vi.stubEnv(name, ''));
}
describe('Learning Engine readiness', () => {
it('fails closed when default narration has no managed TTS provider', async () => {
await configureEngine();
const { inspectLearningReadiness } = await import('@/lib/makelore-runtime/health');
const readiness = await inspectLearningReadiness();
expect(readiness.ready).toBe(false);
expect(readiness.checks.llmProvider).toEqual({ ok: true });
expect(readiness.checks.ttsProvider).toEqual({
ok: false,
detail: 'No enabled server-managed TTS provider is configured',
});
});
it('becomes ready when both LLM and TTS providers are managed', async () => {
await configureEngine();
vi.stubEnv('TTS_OPENAI_API_KEY', 'test-tts-key');
vi.resetModules();
const { inspectLearningReadiness } = await import('@/lib/makelore-runtime/health');
const readiness = await inspectLearningReadiness();
expect(readiness.ready).toBe(true);
expect(readiness.checks.ttsProvider).toEqual({ ok: true });
});
});