Files
descrybe/apps/web/src/lib/merchant-copy.test.ts
T
greeneclipseandClaude Fable 5 9a839d6d13 Store category prompts as EXACT split legacy text, no boilerplate
The per-category prompt editor showed English machine boilerplate
("Role: description. Build JSON …", schema intro, {{var}} context lines)
because seed/sync baked the render framing into categories.prompt. Now the
stored overlay is exactly the legacy wp_product_categories.sql content,
split into the three sections a user would type themselves:

  --- Title ---        Slovenian naming formula
  --- Description ---  legacy <H2>/<p>/<ul> body structure
  --- Meta ---         legacy metaDescription instruction

Schema, role framing, and Name/Description/Category/Attrs product context
stay render-time only (system template + ensureCategoryEnhanceUserContext),
where they already existed.

- SplitLegacyCombinedEnhancePrompt: non-legacy input now returns "" —
  categories without seed/legacy content get their override CLEARED
  (company default) instead of being stuffed with the canonical template
  (e.g. parent categories like "Bela tehnika" absent from the SQL).
- CategoryEnhancePromptNeedsRepair flags stored boilerplate ("parsed as
  JSON", "Build JSON", retired Attributes section) so Sync rewrites old
  data to the clean shape; repair supports clearing (prompt = '{}').
- seed-a1 apply-category-prompts skips instead of writing template text.
- Web editor compose stores only the user's section text: empty sections
  keep bare markers, default bodies and the default preamble are never
  persisted (DEFAULT_SECTION_BODIES removed).
- Verified locally: apply rewrote 238 A1+Demo categories (216 exact
  splits, 22 cleared), zero boilerplate matches in DB, idempotent re-run
  (would_update=0).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-18 00:53:26 +02:00

77 lines
2.9 KiB
TypeScript

/**
* Merchant-facing copy: no A1 / seeded-company, cutover jargon, ETL/blobs/domain,
* or brand-logo API paths in customer-visible strings.
*/
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { UI_LOCALES } from "./i18n/locales.ts";
import { en } from "./i18n/messages/en.ts";
import { loadAllMessages, messagesFor } from "./i18n/messages/catalog.ts";
import { DEFAULT_ENHANCE_PREAMBLE } from "./categories/prompt-sections.ts";
const CUSTOMER_DEMO_EMPTY_KEYS = ["dashboard.demoEmptyHint", "dashboard.demoEmptyMessage"] as const;
const CUSTOMER_ETL_KEYS = [
"etl.gaps.title",
"etl.gaps.message",
"etl.gaps.blobs.title",
"etl.gaps.blobs.body",
"etl.gaps.blobs.countHint",
"etl.gaps.jobs.body",
"etl.gaps.jobs.emptyHint",
"etl.gaps.jobs.migratedHint",
"etl.gaps.woo.body"
] as const;
describe("customer-visible copy leaks", () => {
it("English demo empty, hypercare, ETL, and logo placeholder stay merchant-facing", () => {
for (const key of CUSTOMER_DEMO_EMPTY_KEYS) {
assert.doesNotMatch(en[key], /\bA1\b/i, key);
assert.doesNotMatch(en[key], /seeded company/i, key);
}
assert.doesNotMatch(en["hypercare.report.title"], /cutover|hypercare/i);
assert.doesNotMatch(en["hypercare.report.message"], /cutover|hypercare/i);
for (const key of CUSTOMER_ETL_KEYS) {
assert.doesNotMatch(en[key], /\bETL\b/, key);
assert.doesNotMatch(en[key], /\bblobs?\b/i, key);
assert.doesNotMatch(en[key], /\bdomain\b/i, key);
assert.doesNotMatch(en[key], /cutover/i, key);
}
assert.doesNotMatch(en["brand.placeholder.logoUrl"], /\/api\/brand\/logo\/files/i);
});
it("every UI locale keeps demo empty, hypercare title, ETL, and logo copy merchant-facing", async () => {
await loadAllMessages();
for (const { code } of UI_LOCALES) {
const pack = code === "en" ? en : messagesFor(code);
for (const key of CUSTOMER_DEMO_EMPTY_KEYS) {
const text = String(pack[key] ?? "");
assert.doesNotMatch(text, /\bA1\b/i, `${code}:${key}`);
assert.doesNotMatch(text, /seeded company/i, `${code}:${key}`);
}
assert.doesNotMatch(
String(pack["hypercare.report.title"] ?? ""),
/cutover|hypercare/i,
`${code}:hypercare.report.title`
);
for (const key of CUSTOMER_ETL_KEYS) {
const text = String(pack[key] ?? "");
assert.doesNotMatch(text, /\bETL\b/, `${code}:${key}`);
assert.doesNotMatch(text, /\bblobs?\b/i, `${code}:${key}`);
assert.doesNotMatch(text, /\bdomain\b/i, `${code}:${key}`);
}
assert.doesNotMatch(
String(pack["brand.placeholder.logoUrl"] ?? ""),
/\/api\/brand\/logo\/files/i,
`${code}:brand.placeholder.logoUrl`
);
}
});
it("category prompt defaults hide JSON schema jargon from customer text", () => {
assert.doesNotMatch(DEFAULT_ENHANCE_PREAMBLE, /system schema/i);
assert.doesNotMatch(DEFAULT_ENHANCE_PREAMBLE, /your reply is parsed as json/i);
assert.doesNotMatch(DEFAULT_ENHANCE_PREAMBLE, /build json/i);
});
});