diff --git a/services/our/.dockerignore b/services/our/.dockerignore index 01f06dc..eef653a 100644 --- a/services/our/.dockerignore +++ b/services/our/.dockerignore @@ -1,4 +1,3 @@ -dist vibeui venv src/test diff --git a/services/our/src/tests/fixtures/sample-short.mp4 b/services/our/src/tests/fixtures/sample-short.mp4 new file mode 100644 index 0000000..1f58377 Binary files /dev/null and b/services/our/src/tests/fixtures/sample-short.mp4 differ diff --git a/services/our/src/tests/runInferenceOnFrame.unit.test.ts b/services/our/src/tests/runInferenceOnFrame.unit.test.ts deleted file mode 100644 index d961261..0000000 --- a/services/our/src/tests/runInferenceOnFrame.unit.test.ts +++ /dev/null @@ -1,107 +0,0 @@ -// import { describe, it, expect, vi } from 'vitest'; -// import { runInferenceOnFrame } from '../utils/vibeui'; -// import { -// type InferenceSession, -// type Tensor, -// } from 'onnxruntime-node' - -// type DetectionOutput = { -// bbox: [number, number, number, number]; -// confidence: number; -// classIndex: number; -// }; - -// describe('runInferenceOnFrame', () => { -// it('parses detections and filters by confidence, rounds classIndex, includes out-of-range classes', async () => { -// // Mock session -// const mockSession = { -// inputNames: ['input'], -// outputNames: ['output'], -// run: vi.fn().mockResolvedValue({ -// output: { -// data: new Float32Array([ -// 0.1, 0.2, 0.3, 0.4, 0.5, 10, // valid detection -// 0.2, 0.3, 0.4, 0.5, 0.2, 5, // confidence too low, filtered out -// 0.3, 0.4, 0.5, 0.6, 0.9, 54 // class 54 out of range, but included -// ]), -// dims: [3, 6] -// } -// }), -// } as unknown as InferenceSession; - -// // Mock tensor input, content irrelevant here -// const mockTensor = {} as Tensor; - -// const detections = await runInferenceOnFrame(mockSession, mockTensor); - -// expect(detections).toHaveLength(2); -// expect(detections[0]).toEqual({ -// bbox: [0.1, 0.2, 0.3, 0.4], -// confidence: 0.5, -// classIndex: 10, -// }); -// expect(detections[1]).toEqual({ -// bbox: [0.3, 0.4, 0.5, 0.6], -// confidence: 0.9, -// classIndex: 54, -// }); -// }); - -// it('throws if output missing or data is wrong type', async () => { -// const badSession = { -// inputNames: ['input'], -// outputNames: ['output'], -// run: vi.fn().mockResolvedValue({ -// output: { -// data: [1, 2, 3], // not Float32Array -// dims: [1, 6] -// } -// }), -// } as unknown as InferenceSession; - -// await expect(runInferenceOnFrame(badSession, {} as Tensor)).rejects.toThrow( -// 'Unexpected model output format' -// ); -// }); -// }); - - - -import { describe, it, expect } from 'vitest'; -import fs from 'fs/promises'; -import path, { resolve } from 'path'; -import ort from 'onnxruntime-node'; -import sharp from 'sharp'; -import { preprocessImage, runModelInference } from '../utils/vibeui'; - - -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_PATH = resolve(VIBEUI_DIR, 'vibeui.onnx'); -const IMAGE_PATH = resolve(FIXTURE_DIR, 'prediction/frames/000001.jpg'); - - -describe.skip('runInferenceOnFrame integration', () => { - it('runs inference on real image and returns valid detections', async () => { - // Load ONNX model session - const session = await ort.InferenceSession.create(MODEL_PATH); - - // Prepare input tensor from JPG image - const inputTensor = await preprocessImage(IMAGE_PATH); - - // Run inference - const detections = await runModelInference(session, inputTensor); - - // Check output is not empty and class indices are within range - expect(detections.length).toBeGreaterThan(0); - for (const det of detections) { - expect(det.confidence).toBeGreaterThan(0.3); - expect(det.classIndex).toBeGreaterThanOrEqual(0); - expect(det.classIndex).toBeLessThan(19); // since you have 19 classes - expect(det.bbox).toHaveLength(4); - } - }); -}); diff --git a/services/our/src/tests/vibeuiInference.integration.test.ts b/services/our/src/tests/vibeuiInference.integration.test.ts new file mode 100644 index 0000000..d5e6d28 --- /dev/null +++ b/services/our/src/tests/vibeuiInference.integration.test.ts @@ -0,0 +1,26 @@ +import { describe, it, expect } from 'vitest'; +import fs from 'fs/promises'; +import path, { resolve } from 'path'; +import ort from 'onnxruntime-node'; +import sharp from 'sharp'; +import { preprocessImage, inference } from '../utils/vibeui'; + + +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-short.mp4'); + + +describe('inference integration', () => { + it('runs inference on real video and returns valid detections', { timeout: 60000 }, async () => { + + // Run inference + const output = await inference(VIDEO); + + // Check output is not empty and class indices are within range + expect(output).toContain('/runs/') + + }); +});