import { describe, it, expect } from "vitest"; import { useSearch } from "../composables/useSearch"; import type { Template } from "../types/template"; import type { Stack } from "../types/stack"; // Performance benchmarks describe("MiniSearch Performance Benchmarks", () => { // Generate large dataset function generateLargeDataset(templateCount: number = 600) { const templates: Template[] = Array.from( { length: templateCount }, (_, i) => ({ name: `template-${i}`, type: ["agent", "command", "mcp", "setting", "hook", "skill"][ i % 6 ] as any, description: `Template ${i} with various descriptions and keywords`, content: `Content for template ${i}`, }), ); const stacks: Stack[] = Array.from({ length: 50 }, (_, i) => ({ id: `stack-${i}`, name: `Stack ${i}`, description: `Stack description ${i}`, icon: "ph-package", category: "custom", templates: Array.from({ length: 3 }, (_, j) => ({ type: "agent", name: `template-${(i * 3 + j) % templateCount}`, })), tags: ["tag1", "tag2"], credits: "Test credits", })); return { templates, stacks }; } it("indexes 600+ items in <100ms", () => { const { templates, stacks } = generateLargeDataset(600); const { performSearch } = useSearch(); const start = performance.now(); performSearch("test", templates, stacks); const duration = performance.now() - start; expect(duration).toBeLessThan(100); }); it("searches in <50ms for exact match", () => { const { templates, stacks } = generateLargeDataset(600); const { performSearch } = useSearch(); performSearch("template-1", templates, stacks); const start = performance.now(); performSearch("template-1", templates, stacks); const duration = performance.now() - start; expect(duration).toBeLessThan(50); }); it("fuzzy search completes in <50ms", () => { const { templates, stacks } = generateLargeDataset(600); const { performSearch } = useSearch(); performSearch("tmpl", templates, stacks); const start = performance.now(); performSearch("tmpl", templates, stacks); const duration = performance.now() - start; expect(duration).toBeLessThan(50); }); it("handles complex queries efficiently", () => { const { templates, stacks } = generateLargeDataset(600); const { performSearch } = useSearch(); const start = performance.now(); performSearch("template agent description", templates, stacks); const duration = performance.now() - start; expect(duration).toBeLessThan(100); }); it("returns max 8 results consistently", () => { const { templates, stacks } = generateLargeDataset(600); const { performSearch, results } = useSearch(); performSearch("template", templates, stacks); expect(results.value.length).toBeLessThanOrEqual(8); performSearch("agent", templates, stacks); expect(results.value.length).toBeLessThanOrEqual(8); }); });