fp/services/our/src/tests/vibeui.integration.test.ts
2025-08-25 20:18:56 -08:00

66 lines
2.2 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll, beforeEach, vi, type Mock } from 'vitest';
import { vibeuiInference, processLabelFiles, getModelClasses } from '../utils/vibeui';
import { resolve, join } from 'node:path';
import { readdir, readFile, rm } from 'node:fs/promises';
import { readJson } from 'fs-extra';
import { DataYaml } from '../utils/funscripts';
import logger from '../utils/logger';
const __dirname = import.meta.dirname;
const FIXTURE_DIR = resolve(__dirname, 'fixtures');
const DIST_DIR = resolve(__dirname, '..', '..', 'dist');
const VIBEUI_DIR = resolve(DIST_DIR, 'vibeui');
const VIDEO = resolve(FIXTURE_DIR, 'sample.mp4');
const MODEL = resolve(VIBEUI_DIR, 'vibeui.onnx');
describe('[integration] vibeuiInference', () => {
let outputPath: string;
beforeAll(async () => {
outputPath = await vibeuiInference(MODEL, VIDEO);
logger.info(`outputPath=${outputPath}`)
}, 35_000);
afterAll(async () => {
// await rm(outputPath, { recursive: true, force: true });
logger.info('@todo cleanup')
});
it('outputs detection labels and frames', async () => {
const frames = await readdir(join(outputPath, 'frames'));
const labels = await readdir(join(outputPath, 'labels'));
expect(frames.length).toBeGreaterThan(0);
expect(labels.length).toBeGreaterThan(0);
});
it('writes properly formatted label files', async () => {
const labelFile = join(outputPath, 'labels', '1.txt');
const content = await readFile(labelFile, 'utf8');
const firstLine = content.split('\n')[0].trim().replace(/\r/g, '');
logger.info('First line content:', JSON.stringify(firstLine));
// Expect initial class number + exactly 5 floats/ints after it (6 total numbers)
expect(firstLine).toMatch(/^\d+( (-?\d+(\.\d+)?)){5}$/);
});
it('contains only 1-10 lines', async () => {
const labelFile = join(outputPath, 'labels', '1.txt');
const content = await readFile(labelFile, 'utf8');
const lines = content
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0); // ignore empty lines
expect(lines.length).toBeGreaterThanOrEqual(1);
expect(lines.length).toBeLessThanOrEqual(10);
});
});