Files
openmaic/OpenMAIC/tests/generation/foreground-session.test.ts
2026-08-16 14:58:47 +08:00

84 lines
2.5 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { createForegroundGenerationSession } from '@/lib/generation/foreground-session';
import type { SelectedCourseMaterial } from '@/lib/types/generation';
function material(
id: string,
name: string,
order: number,
type = 'application/pdf',
): SelectedCourseMaterial {
const file = { name, size: 100 + order, lastModified: order, type } as File;
return {
id,
file,
name,
size: file.size,
lastModified: file.lastModified,
type,
order,
};
}
describe('createForegroundGenerationSession', () => {
it('persists materials in display order and maps foreground feature flags', async () => {
const storeDocument = vi.fn(async (file: File) => `stored:${file.name}`);
const session = await createForegroundGenerationSession({
sessionId: 'session-1',
requirement: ' Build an interactive safety course ',
webSearch: true,
interactiveMode: true,
taskEngineMode: true,
courseMaterials: [material('b', 'second.pdf', 2), material('a', 'first.pdf', 1)],
pdfProviderId: 'unpdf',
pdfProviderConfig: { baseUrl: 'local' },
storeDocument,
});
expect(storeDocument.mock.calls.map(([file]) => file.name)).toEqual([
'first.pdf',
'second.pdf',
]);
expect(session.requirements).toEqual({
requirement: 'Build an interactive safety course',
webSearch: true,
interactiveMode: true,
taskEngineMode: true,
});
expect(session.documentSources).toEqual([
expect.objectContaining({
id: 'a',
order: 1,
storageKey: 'stored:first.pdf',
providerId: 'unpdf',
}),
expect.objectContaining({
id: 'b',
order: 2,
storageKey: 'stored:second.pdf',
providerId: 'unpdf',
}),
]);
expect(session.taskEngineMode).toBe(true);
expect(session.previewPhase).toBe('preparing');
});
it('omits disabled optional requirements and supports a material-free session', async () => {
const session = await createForegroundGenerationSession({
sessionId: 'session-2',
requirement: 'Photosynthesis',
webSearch: false,
interactiveMode: false,
taskEngineMode: false,
courseMaterials: [],
storeDocument: vi.fn(),
});
expect(session.requirements).toEqual({ requirement: 'Photosynthesis' });
expect(session.documentSources).toEqual([]);
expect(session.pdfProviderId).toBeUndefined();
expect(session.pdfProviderConfig).toBeUndefined();
});
});