// node --test fingerprints.test.mjs import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import zlib from 'node:zlib'; import { classify, RULES } from './fingerprints.mjs'; import { CONTROLS } from './controls.mjs'; const fx = new URL('./fixtures/controls.jsonl.gz', import.meta.url); const pages = new Map(zlib.gunzipSync(fs.readFileSync(fx)).toString('utf8').split('\n').filter(Boolean).map((l) => { const r = JSON.parse(l); return [r.domain, r]; })); test('every control has its real captured page', () => { for (const c of CONTROLS) assert.ok(pages.has(c.domain), `no capture for ${c.domain}`); }); for (const c of CONTROLS) { test(`control ${c.domain} -> ${c.platform || c.kind}`, () => { const got = classify(pages.get(c.domain)); if (c.kind) assert.equal(got.kind, c.kind, JSON.stringify(got)); else { assert.equal(got.kind, 'site', JSON.stringify(got)); assert.equal(got.platform, c.platform, JSON.stringify(got)); } }); } // Constructed negatives (written here, not captured): text and links ABOUT a builder must not count as built WITH it. const page = (body, head = '') => ({ ok: true, status: 200, domain: 'example-negative.com', finalUrl: 'https://example-negative.com/', headers: { server: 'nginx' }, html: `Review of AI builders${head}${body}${'

Long article text about website tools and what they cost for a small business owner.

'.repeat(30)}` }); test('a WordPress post reviewing Lovable and Bolt stays WordPress', () => { const r = page('

We built a site with Lovable (https://lovable.dev) and also made with bolt, see bolt.new.

Lovable', ''); const got = classify(r); assert.equal(got.platform, 'WordPress'); }); test('a hand-coded article that mentions v0 and Base44 is not attributed to them', () => { const got = classify(page('

Created with v0? Or Base44? Compare base44.com and v0.app pricing.

')); assert.equal(got.platform, 'Custom / unidentified'); }); test('a red control: removing the Lovable rule makes the Lovable controls fail', () => { const i = RULES.findIndex((r) => r.platform === 'Lovable'); const saved = RULES.splice(i, 1)[0]; try { const got = classify(pages.get('allseasonscomfort.dev')); assert.notEqual(got.platform, 'Lovable'); } finally { RULES.splice(i, 0, saved); } }); test('the network block page is never counted as a site', () => { const got = classify({ ok: true, status: 200, domain: 'x.com', finalUrl: 'https://www.safebrowse.io/warn.html?url=http://x.com/', headers: {}, html: '

This site could be risky

' }); assert.equal(got.kind, 'blocked'); });