deckhearth/test/lib/card-visual-match.test.js
varutasu 8f09ed1ef6
feat(scanner): Layer-0 visual catalog search (Phase 3) (#160)
Add pgvector embeddings on cards, server-side cohere/embed-v4.0 via AI
Gateway, kNN identify route, and L0→L1→L2 client orchestration with
empty-index fast escalate and id-cursor backfill job.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 21:46:39 -05:00

40 lines
1.1 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { resolveVisualCandidates } from '../../lib/card-visual-match.js';
describe('resolveVisualCandidates', () => {
const baseCard = {
id: 1,
name: 'Lightning Bolt',
set_name: 'Alpha',
set_code: 'lea',
card_number: '161',
game: 'mtg',
rarity: 'common',
image_url: 'https://example.com/bolt.jpg',
card_type: 'Instant',
mana_cost: '{R}',
power: null,
};
it('escalates when no candidates remain', () => {
expect(resolveVisualCandidates([]).type).toBe('escalate');
});
it('auto-matches a clear visual winner', () => {
const result = resolveVisualCandidates([
{ ...baseCard, sim: 0.9 },
{ ...baseCard, id: 2, sim: 0.7 },
]);
expect(result.type).toBe('matched');
expect(result.card.id).toBe(1);
});
it('opens disambiguation when top matches are close', () => {
const result = resolveVisualCandidates([
{ ...baseCard, sim: 0.8 },
{ ...baseCard, id: 2, set_name: 'Beta', sim: 0.77 },
]);
expect(result.type).toBe('disambiguation');
expect(result.matches).toHaveLength(2);
});
});