From b314b1b112102e2692bd3e226d993a2409b220ed Mon Sep 17 00:00:00 2001 From: backryun Date: Thu, 13 Aug 2026 07:48:24 -0300 Subject: [PATCH] test(radar): move D12 guard out of OSS --- tests/unit/radar-claim-buttons.test.ts | 37 +++++--------------------- tests/unit/radar-key-input.test.ts | 35 +++++------------------- 2 files changed, 13 insertions(+), 59 deletions(-) diff --git a/tests/unit/radar-claim-buttons.test.ts b/tests/unit/radar-claim-buttons.test.ts index 240e0670b5..7ae3d0ef31 100644 --- a/tests/unit/radar-claim-buttons.test.ts +++ b/tests/unit/radar-claim-buttons.test.ts @@ -23,10 +23,7 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; -const PAGE_PATH = path.resolve( - process.cwd(), - "src/app/(dashboard)/dashboard/radar/page.tsx" -); +const PAGE_PATH = path.resolve(process.cwd(), "src/app/(dashboard)/dashboard/radar/page.tsx"); const PAGE_SRC = fs.readFileSync(PAGE_PATH, "utf-8"); const NEW_KEYS = [ @@ -57,33 +54,26 @@ test("radar page: claim/plans links are state, never a hardcoded external URL li }); test("radar page: both buttons open in a new tab safely", () => { - const contributorAnchor = PAGE_SRC.match( - /href=\{contributorClaimUrl\}[\s\S]{0,120}/ - )?.[0]; + const contributorAnchor = PAGE_SRC.match(/href=\{contributorClaimUrl\}[\s\S]{0,120}/)?.[0]; const supporterAnchor = PAGE_SRC.match(/href=\{supporterPlansUrl\}[\s\S]{0,120}/)?.[0]; assert.ok(contributorAnchor, "contributorClaimUrl anchor must exist"); assert.ok(supporterAnchor, "supporterPlansUrl anchor must exist"); for (const anchor of [contributorAnchor, supporterAnchor]) { assert.ok(anchor!.includes('target="_blank"'), "must open in a new tab"); - assert.ok( - anchor!.includes('rel="noopener noreferrer"'), - "must set rel=noopener noreferrer" - ); + assert.ok(anchor!.includes('rel="noopener noreferrer"'), "must set rel=noopener noreferrer"); } }); test("radar page: references the 5 new claim-section t(...) keys", () => { for (const key of NEW_KEYS) { - assert.ok( - PAGE_SRC.includes(`t("${key}")`), - `page.tsx must reference t("${key}")` - ); + assert.ok(PAGE_SRC.includes(`t("${key}")`), `page.tsx must reference t("${key}")`); } }); test("radar page + all 43 locale files: no price/monetary value in the claim section copy (D14)", () => { // D14: no pricing anywhere in the OSS repo, only a link to the plans page. - const PRICE_PATTERN = /\$\s?\d|R\$\s?\d|\d+[.,]\d{2}\s?(USD|BRL|EUR)|\b(lifetime|life-time)\b.{0,20}\$/i; + const PRICE_PATTERN = + /\$\s?\d|R\$\s?\d|\d+[.,]\d{2}\s?(USD|BRL|EUR)|\b(lifetime|life-time)\b.{0,20}\$/i; assert.ok(!PRICE_PATTERN.test(PAGE_SRC), "page.tsx must not contain a price/monetary value"); const messagesDir = path.resolve(process.cwd(), "src/i18n/messages"); @@ -105,18 +95,3 @@ test("radar page + all 43 locale files: no price/monetary value in the claim sec } } }); - -test("no OSS file mentions the word 'freellmapi'", () => { - // Repo-wide guard scoped to the files this task touches — the full - // repo-wide ban is enforced elsewhere; this is a local regression check - // for the files this feature added/edited. - const filesToCheck = [ - PAGE_PATH, - path.resolve(process.cwd(), "src/lib/radar/links.ts"), - path.resolve(process.cwd(), "src/app/api/radar/settings/route.ts"), - ]; - for (const file of filesToCheck) { - const src = fs.readFileSync(file, "utf-8"); - assert.ok(!/freellmapi/i.test(src), `${file} must not mention freellmapi`); - } -}); diff --git a/tests/unit/radar-key-input.test.ts b/tests/unit/radar-key-input.test.ts index 1a5474381a..0c73d0b1c3 100644 --- a/tests/unit/radar-key-input.test.ts +++ b/tests/unit/radar-key-input.test.ts @@ -19,8 +19,7 @@ * - the already-activated state shows the masked key (never the raw one) * with a "change key" escape hatch; * - the 4 new t("...") keys exist (non-empty, no price) in en.json and all - * 43 locale files; - * - no OSS file mentions "freellmapi". + * 43 locale files. */ import test from "node:test"; @@ -28,10 +27,7 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; -const PAGE_PATH = path.resolve( - process.cwd(), - "src/app/(dashboard)/dashboard/radar/page.tsx" -); +const PAGE_PATH = path.resolve(process.cwd(), "src/app/(dashboard)/dashboard/radar/page.tsx"); const PAGE_SRC = fs.readFileSync(PAGE_PATH, "utf-8"); const NEW_KEYS = [ @@ -57,10 +53,7 @@ test("radar page: submitting a pasted key sends optIn+supporterKey together", () /const handleSubmitKey = useCallback\(async \(\) => \{[\s\S]*?\n {2}\}, \[[^\]]*\]\);/ )?.[0]; assert.ok(submitFn, "handleSubmitKey callback must exist"); - assert.ok( - submitFn!.includes("/api/radar/settings"), - "must POST to /api/radar/settings" - ); + assert.ok(submitFn!.includes("/api/radar/settings"), "must POST to /api/radar/settings"); assert.ok( /optIn:\s*true/.test(submitFn!), "pasting a key must also opt in (unlocks the activation screen)" @@ -100,21 +93,19 @@ test("radar page: 'change key' escape hatch exists to replace an already-set key ); assert.ok( PAGE_SRC.includes(`t("changeKeyButton")`), - "page.tsx must reference t(\"changeKeyButton\")" + 'page.tsx must reference t("changeKeyButton")' ); }); test("radar page: references the 4 new key-input t(...) keys", () => { for (const key of NEW_KEYS) { - assert.ok( - PAGE_SRC.includes(`t("${key}")`), - `page.tsx must reference t("${key}")` - ); + assert.ok(PAGE_SRC.includes(`t("${key}")`), `page.tsx must reference t("${key}")`); } }); test("radar page + all 43 locale files: no price/monetary value in the key-input copy (D14)", () => { - const PRICE_PATTERN = /\$\s?\d|R\$\s?\d|\d+[.,]\d{2}\s?(USD|BRL|EUR)|\b(lifetime|life-time)\b.{0,20}\$/i; + const PRICE_PATTERN = + /\$\s?\d|R\$\s?\d|\d+[.,]\d{2}\s?(USD|BRL|EUR)|\b(lifetime|life-time)\b.{0,20}\$/i; assert.ok(!PRICE_PATTERN.test(PAGE_SRC), "page.tsx must not contain a price/monetary value"); const messagesDir = path.resolve(process.cwd(), "src/i18n/messages"); @@ -140,15 +131,3 @@ test("radar page + all 43 locale files: no price/monetary value in the key-input } } }); - -test("no OSS file mentions the word 'freellmapi'", () => { - const filesToCheck = [ - PAGE_PATH, - path.resolve(process.cwd(), "src/lib/radar/supporterKey.ts"), - path.resolve(process.cwd(), "src/app/api/radar/settings/route.ts"), - ]; - for (const file of filesToCheck) { - const src = fs.readFileSync(file, "utf-8"); - assert.ok(!/freellmapi/i.test(src), `${file} must not mention freellmapi`); - } -});