test(radar): move D12 guard out of OSS

This commit is contained in:
backryun
2026-08-13 07:48:24 -03:00
committed by Xiangzhe
parent b334d2d05a
commit b314b1b112
2 changed files with 13 additions and 59 deletions

View File

@@ -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`);
}
});

View File

@@ -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`);
}
});