|
| 1 | +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
| 2 | +import { existsSync, rmSync } from 'node:fs'; |
| 3 | +import { join } from 'node:path'; |
| 4 | +import { tmpdir } from 'node:os'; |
| 5 | +import { startTestServer, type TestServer } from './fixtures/server.js'; |
| 6 | +import { runPipeline } from '../../packages/core/src/pipeline.js'; |
| 7 | +import { VIRTUAL_TRYON_DIFF } from './fixtures/virtual-tryon-diff.js'; |
| 8 | +import type { GitGlimpseConfig } from '../../packages/core/src/config/schema.js'; |
| 9 | + |
| 10 | +const HAS_API_KEY = !!process.env['ANTHROPIC_API_KEY']; |
| 11 | + |
| 12 | +let server: TestServer; |
| 13 | +let outputDir: string; |
| 14 | + |
| 15 | +beforeAll(async () => { |
| 16 | + server = await startTestServer(); |
| 17 | + outputDir = join(tmpdir(), `git-glimpse-llm-test-${Date.now()}`); |
| 18 | +}, 15000); |
| 19 | + |
| 20 | +afterAll(async () => { |
| 21 | + if (server) await server.close(); |
| 22 | + if (existsSync(outputDir)) { |
| 23 | + rmSync(outputDir, { recursive: true, force: true }); |
| 24 | + } |
| 25 | +}); |
| 26 | + |
| 27 | +const config: GitGlimpseConfig = { |
| 28 | + app: {}, |
| 29 | + // Map the diff's file path to / so the LLM navigates to the test server root |
| 30 | + routeMap: { |
| 31 | + 'src/app/products/page.tsx': '/', |
| 32 | + }, |
| 33 | + recording: { |
| 34 | + viewport: { width: 1280, height: 720 }, |
| 35 | + format: 'gif', |
| 36 | + maxDuration: 30, |
| 37 | + deviceScaleFactor: 1, |
| 38 | + }, |
| 39 | + llm: { |
| 40 | + provider: 'anthropic', |
| 41 | + model: 'claude-sonnet-4-6', |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +describe.skipIf(!HAS_API_KEY)('LLM pipeline (real Anthropic + Playwright + FFmpeg)', () => { |
| 46 | + it('generates a working demo GIF from a fixture diff', async () => { |
| 47 | + const result = await runPipeline({ |
| 48 | + diff: VIRTUAL_TRYON_DIFF, |
| 49 | + baseUrl: server.url, |
| 50 | + outputDir, |
| 51 | + config, |
| 52 | + }); |
| 53 | + |
| 54 | + // LLM produced a meaningful analysis |
| 55 | + expect(result.analysis.changeDescription).toBeTruthy(); |
| 56 | + expect(result.analysis.suggestedDemoFlow).toBeTruthy(); |
| 57 | + expect(result.analysis.changedFiles).toContain('src/app/products/page.tsx'); |
| 58 | + |
| 59 | + // LLM produced a structurally valid script |
| 60 | + expect(result.script).toContain('export async function demo'); |
| 61 | + expect(result.script).toContain('page'); |
| 62 | + |
| 63 | + // Attempt count is within retry budget |
| 64 | + expect(result.attempts).toBeGreaterThanOrEqual(1); |
| 65 | + expect(result.attempts).toBeLessThanOrEqual(3); |
| 66 | + |
| 67 | + if (!result.success) { |
| 68 | + // Surface LLM/Playwright errors to make failures easy to diagnose |
| 69 | + console.error('Pipeline errors:', result.errors); |
| 70 | + console.error('Generated script:\n', result.script); |
| 71 | + } |
| 72 | + |
| 73 | + // Full pipeline succeeded — GIF was recorded |
| 74 | + expect(result.success).toBe(true); |
| 75 | + expect(result.recording).toBeDefined(); |
| 76 | + expect(result.recording!.path).toMatch(/\.gif$/); |
| 77 | + expect(existsSync(result.recording!.path)).toBe(true); |
| 78 | + expect(result.recording!.sizeMB).toBeGreaterThan(0); |
| 79 | + expect(result.recording!.sizeMB).toBeLessThan(10); |
| 80 | + expect(result.recording!.duration).toBeGreaterThan(0); |
| 81 | + expect(result.recording!.duration).toBeLessThan(30); |
| 82 | + }, 120000); |
| 83 | +}); |
0 commit comments