feat(cms): copyable legal validation prompt in the legal page editor (MITHOME-113)
buildLegalValidationPrompt() is the single review template: the criteria (meaning, GDPR terminology, obligation strength, preserved markers, clarity), a severity table output with a final verdict, and the Hungarian/English text of every section paired by id, missing English flagged as high severity. The legal page sidebar shows it through the LegalValidationPrompt UI field (hu + en read from REST with draft=true and no locale fallback) with copy and refresh buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
329e2e3403
commit
acd1ff2ed9
@@ -0,0 +1,40 @@
|
||||
import { buildLegalValidationPrompt, hasEnglishContent } from './legal-validation-prompt'
|
||||
|
||||
const hu = {
|
||||
title: 'Adatvédelmi Tájékoztató',
|
||||
lastUpdated: '2026. augusztus 22.',
|
||||
sections: [
|
||||
{ id: 'bevezetes', title: '1. Bevezetés', content: 'A mozdIT Bt. mint adatkezelő…' },
|
||||
{ id: 'jogok', title: '5. Az érintettek jogai', content: 'Az érintettek bármikor…' },
|
||||
],
|
||||
}
|
||||
const en = {
|
||||
title: 'Privacy Notice',
|
||||
lastUpdated: '22 August 2026',
|
||||
sections: [{ id: 'bevezetes', title: '1. Introduction', content: 'mozdIT Bt., as controller…' }],
|
||||
}
|
||||
|
||||
describe('buildLegalValidationPrompt (MITHOME-113)', () => {
|
||||
const prompt = buildLegalValidationPrompt(hu, en)!
|
||||
|
||||
it('should include every review criterion and the output format', () => {
|
||||
for (const text of ['Meaning equivalence', 'GDPR', 'Strength of obligations', 'placeholders', 'Severity (high / medium / low)', 'APPROVE WITH CHANGES', 'not legal advice']) {
|
||||
expect(prompt).toContain(text)
|
||||
}
|
||||
})
|
||||
|
||||
it('should pair every Hungarian section with its English section by id', () => {
|
||||
expect(prompt).toContain('--- Section 1 (bevezetes) ---\n[HU] 1. Bevezetés\nA mozdIT Bt. mint adatkezelő…\n[EN] 1. Introduction\nmozdIT Bt., as controller…')
|
||||
expect(prompt).toContain('Document (EN): Privacy Notice')
|
||||
})
|
||||
|
||||
it('should flag a missing English section as high severity', () => {
|
||||
expect(prompt).toContain('--- Section 2 (jogok) ---')
|
||||
expect(prompt).toMatch(/\[EN\] \(missing — report as high severity\)\n\(missing — report as high severity\)$/)
|
||||
})
|
||||
|
||||
it('should return undefined when there is no English text', () => {
|
||||
expect(buildLegalValidationPrompt(hu, { title: ' ', sections: [{ id: 'bevezetes', title: null, content: '' }] })).toBeUndefined()
|
||||
expect(hasEnglishContent({})).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* MITHOME-113 (design D8): the single template for validating the English
|
||||
* translation of a legal page. Used both by the admin "Validation prompt"
|
||||
* panel (src/components/admin/LegalValidationPrompt.tsx) and by the
|
||||
* project's own multi-model validation, so the two are comparable.
|
||||
*
|
||||
* WHY in code, not in the CMS: the review criteria are a quality rule, not
|
||||
* page content — changes must go through git review so they cannot be
|
||||
* weakened by accident.
|
||||
* WHY English: the most stable instruction language across models; the
|
||||
* document texts stay in their original languages.
|
||||
*/
|
||||
|
||||
export type LegalSection = { id?: string | null; title?: string | null; content?: string | null }
|
||||
export type LegalText = { title?: string | null; lastUpdated?: string | null; sections?: LegalSection[] | null }
|
||||
|
||||
const MISSING = '(missing — report as high severity)'
|
||||
|
||||
const INSTRUCTIONS = `You are reviewing the English translation of a Hungarian legal document published on the website of mozdIT Bt., a Hungarian IT hosting provider. The Hungarian text is authoritative.
|
||||
|
||||
Check every section for:
|
||||
1. Meaning equivalence — nothing added, omitted or changed: same scope, conditions, numbers, deadlines and retention periods.
|
||||
2. Data-protection terminology consistent with the official English text of the GDPR (e.g. controller, processor, data subject, legal basis, legitimate interest, erasure, restriction of processing) and correct English names of Hungarian authorities and laws.
|
||||
3. Strength of obligations and rights — "shall", "must", "may", "is entitled to" must match the Hungarian.
|
||||
4. Preserved placeholders, e-mail addresses, URLs and formatting markers (**bold**, "•" bullets, line breaks).
|
||||
5. Clarity for an English-speaking reader without changing the legal meaning.
|
||||
|
||||
Output format:
|
||||
- A table with the columns: Section | Severity (high / medium / low) | Issue | Hungarian excerpt | Suggested English wording.
|
||||
High = changes a legal meaning, right or obligation; medium = terminology or ambiguity; low = style.
|
||||
- Then a final verdict — APPROVE, APPROVE WITH CHANGES or REJECT — with a one-sentence justification.
|
||||
Do not rewrite the whole document. Note that this review is not legal advice.`
|
||||
|
||||
const hasText = (value?: string | null) => Boolean(value?.trim())
|
||||
|
||||
export function hasEnglishContent(en: LegalText): boolean {
|
||||
return hasText(en.title) || (en.sections ?? []).some((s) => hasText(s.title) || hasText(s.content))
|
||||
}
|
||||
|
||||
function block(label: string, title?: string | null, content?: string | null) {
|
||||
return `[${label}] ${hasText(title) ? title : MISSING}\n${hasText(content) ? content : MISSING}`
|
||||
}
|
||||
|
||||
/** The review prompt, or undefined when there is no English text to validate. */
|
||||
export function buildLegalValidationPrompt(hu: LegalText, en: LegalText): string | undefined {
|
||||
if (!hasEnglishContent(en)) return undefined
|
||||
const enById = new Map((en.sections ?? []).map((s) => [s.id, s]))
|
||||
|
||||
const header = [
|
||||
`Document (HU): ${hu.title ?? ''}`,
|
||||
`Document (EN): ${hasText(en.title) ? en.title : MISSING}`,
|
||||
`Last updated (HU / EN): ${hu.lastUpdated ?? ''} / ${hasText(en.lastUpdated) ? en.lastUpdated : MISSING}`,
|
||||
].join('\n')
|
||||
|
||||
const sections = (hu.sections ?? []).map((section, index) => {
|
||||
const english = enById.get(section.id) ?? {}
|
||||
return [
|
||||
`--- Section ${index + 1}${section.id ? ` (${section.id})` : ''} ---`,
|
||||
block('HU', section.title, section.content),
|
||||
block('EN', english.title, english.content),
|
||||
].join('\n')
|
||||
})
|
||||
|
||||
return [INSTRUCTIONS, header, ...sections].join('\n\n')
|
||||
}
|
||||
Reference in New Issue
Block a user