SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
1.6 KB · 35 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { qualityScore, documentQuality } from './quality.js';3import { healthFromRuns } from './health.js';4import { childLogger } from '@rareindex/shared';5import type { ConnectorMeta } from './types.js';67const meta = { id: 'x', schemaVersion: '1.0' } as unknown as ConnectorMeta;89describe('quality', () => {10  it('scores expected fields', () => {11    expect(qualityScore({ title: 'a', price: 1, status: 'sold', date: new Date(), images: ['u'], description: 'd', identifiers: { a: 'b' }, category: 'c', currency: 'USD' })).toBe(1);12    expect(qualityScore({ title: 'a' }, ['title', 'price'])).toBe(0.5);13    expect(qualityScore(null)).toBe(0);14  });15  it('flags blocked documents', () => {16    expect(documentQuality({ html: 'Just a moment... Cloudflare', httpStatus: 200 })).toBeLessThan(0.5);17    expect(documentQuality({ html: 'x'.repeat(5000), httpStatus: 200 })).toBeGreaterThanOrEqual(0.8);18    expect(documentQuality({ html: 'x'.repeat(5000), httpStatus: 403 })).toBe(0);19  });20  it('derives health', () => {21    const h = healthFromRuns(22      {23        meta,24        log: childLogger({}),25        fetch: async () => ({}) as never,26        recentRuns: [{ startedAt: new Date(), status: 'success', pagesAttempted: 100, pagesSuccess: 98, recordsRaw: 500, recordsDuplicate: 20, engineStats: { firecrawl: { attempts: 100, success: 91, credits: 100, ms: 1 }, scrapfly: { attempts: 7, success: 7, credits: 7, ms: 1 } }, anomalies: [], error: null }],27      },28      '1.0',29    );30    expect(h.status).toBe('healthy');31    expect(h.success_rate_24h).toBe(0.98);32    expect(h.scrapfly_fallback_rate).toBe(0.07);33  });34});35