mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
test(coach): assert grounding + GLP-1 contract in every locale's prompt
The safety-contract matrix parity test checks rule bodies are non-empty; this asserts the resolved getCoachSystemPrompt(locale) string carries the grounding marker and the GLP-1 dose-safety contract for all six UI locales, closing the gap where a non-EN/DE locale could silently fall back to a weaker EN-plus-footer body.
This commit is contained in:
1 parent
db68f994c2
commit
883383c6a6
1 file changed
+57
@@ -0,0 +1,57 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { getCoachSystemPrompt } from "@/lib/ai/coach/system-prompt";
|
||||
import { loadSafetyContracts } from "@/lib/ai/prompts/safety-contracts";
|
||||
import type { Locale } from "@/lib/i18n/config";
|
||||
|
||||
/**
|
||||
* v1.18.10 (MEDIUM-1) — resolved-Coach-prompt contract parity.
|
||||
*
|
||||
* `safety-contracts-parity.test.ts` asserts every ground-rule BODY in the
|
||||
* matrix is non-empty per locale. This file goes one step further and asserts
|
||||
* the *resolved* `getCoachSystemPrompt(locale)` string — the exact text the
|
||||
* provider sees — carries the grounding + GLP-1 dose-safety contract for EVERY
|
||||
* UI locale, not just de/en. The audit's residual MEDIUM-1 risk was that a
|
||||
* non-EN/DE locale could silently fall back to the EN-plus-footer path (or a
|
||||
* native body that weakened the wording) and ship a less-strict Coach. These
|
||||
* assertions fail the build if that ever happens.
|
||||
*
|
||||
* Markers used:
|
||||
* - grounding: the literal "SNAPSHOT" token, which the grounding rule's
|
||||
* `must_contain` pins in every locale.
|
||||
* - GLP-1 dose safety: the brand registry (Mounjaro / Ozempic), which is
|
||||
* identical across all six locales (an international registry, never
|
||||
* translated) and only ever appears inside the dose-safety contract.
|
||||
*/
|
||||
|
||||
const ALL_LOCALES: Locale[] = ["de", "en", "fr", "es", "it", "pl"];
|
||||
|
||||
describe("resolved Coach system prompt — grounding + GLP-1 per locale", () => {
|
||||
for (const locale of ALL_LOCALES) {
|
||||
it(`${locale} carries a grounding marker`, () => {
|
||||
const prompt = getCoachSystemPrompt(locale);
|
||||
expect(prompt).toContain("SNAPSHOT");
|
||||
});
|
||||
|
||||
it(`${locale} carries the GLP-1 dose-safety contract`, () => {
|
||||
const prompt = getCoachSystemPrompt(locale);
|
||||
// Brand names are identical across locales and only appear in the
|
||||
// dose-safety contract — their presence proves the contract is composed.
|
||||
expect(prompt).toMatch(/Mounjaro/);
|
||||
expect(prompt).toMatch(/Ozempic/);
|
||||
});
|
||||
|
||||
it(`${locale} never silently empties to a bare EN footer`, () => {
|
||||
const prompt = getCoachSystemPrompt(locale);
|
||||
expect(prompt.trim().length).toBeGreaterThan(500);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("GLP-1 brand registry stays identical across locales (marker basis)", () => {
|
||||
const enBrands = loadSafetyContracts("en").glp1_brand_list;
|
||||
it("EN brand list is non-empty (the marker source)", () => {
|
||||
expect(enBrands.length).toBeGreaterThan(0);
|
||||
expect(enBrands).toContain("Mounjaro");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user