feat(cms): require multi-model validation before approving legal translations (MITHOME-113)
Legal pages get a sidebar "legal validation" record (validating models, date, report reference). Their English translation status can only be set to "approved" when at least two distinct models, the date and the report are recorded; page globals are unaffected. The admin description states that model review does not replace legal advice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
822646a82a
commit
329e2e3403
@@ -17,7 +17,7 @@
|
||||
|
||||
## 4. Jogi szövegek többmodelles validálása
|
||||
|
||||
- [ ] 4.1 A `legalValidation` mezőcsoport felvétele a LegalPages-re, valamint az `enTranslationStatus` `validate` szabálya (jogi oldalon `approved` csak teljes validációs rekorddal). Unit tesztek: hiányos rekord → hiba; ≥2 modell + dátum + riport → ok; Global → nincs feltétel. Ellenőrzés: `npm test`.
|
||||
- [x] 4.1 A `legalValidation` mezőcsoport felvétele a LegalPages-re, valamint az `enTranslationStatus` `validate` szabálya (jogi oldalon `approved` csak teljes validációs rekorddal). Unit tesztek: hiányos rekord → hiba; ≥2 modell + dátum + riport → ok; Global → nincs feltétel. Ellenőrzés: `npm test`.
|
||||
- [ ] 4.2 A validációs promptsablon (`src/lib/legal-validation-prompt.ts`) és a `LegalValidationPrompt` admin panel elkészítése (D8): hu+en szakaszpárok REST-ről, csak olvasható mező, „Prompt másolása” gomb, üres angol esetén jelzés; az importMap újragenerálása. Unit tesztek a sablonra (minden szakasz és szempont benne van, a hiányzó angol szakasz jelölve). Ellenőrzés: `npm test`, valamint böngészőben az admin panel megjelenik, és a másolás működik.
|
||||
- [ ] 4.3 A jogi oldalak angol draftjának független validálása legalább két magas szintű modellel (javaslat: Fable 5.1 és Opus 5.5, külön-külön, **a 4.2-es sablon promptjával**, a D7 szempontjai szerint). A megállapítások egyeztetése, a javítások visszavezetése a szótárba, a riport elkészítése (`docs/legal-translation-validation.md`). A modellek futtatása előtt a felhasználó jóváhagyása szükséges. Ellenőrzés: a riportban minden „magas” súlyosságú megállapítás le van zárva.
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload'
|
||||
|
||||
import { collectionVersions } from '../lib/payload-versions'
|
||||
import { translationStatusField } from '../globals/fields/translationStatus'
|
||||
import { validateLegalApproval } from '../lib/legal-validation'
|
||||
|
||||
/**
|
||||
* Mirrors LegalPageContent (proto/src/content/types.ts) — MITHOME-88.
|
||||
@@ -56,6 +57,24 @@ export const LegalPages: CollectionConfig = {
|
||||
{ name: 'content', type: 'textarea', required: true, localized: true },
|
||||
],
|
||||
},
|
||||
translationStatusField(),
|
||||
// MITHOME-113: legal translations need a recorded multi-model review
|
||||
// before they can be approved (src/lib/legal-validation.ts).
|
||||
translationStatusField(validateLegalApproval),
|
||||
{
|
||||
name: 'legalValidation',
|
||||
label: 'Jogi validáció (angol fordítás)',
|
||||
type: 'group',
|
||||
admin: {
|
||||
position: 'sidebar',
|
||||
description:
|
||||
'Az angol fordítás csak akkor hagyható jóvá, ha legalább két független, magas szintű modell ellenőrizte. ' +
|
||||
'A modell-validáció nem helyettesíti a jogi szakvéleményt.',
|
||||
},
|
||||
fields: [
|
||||
{ name: 'models', label: 'Validáló modellek', type: 'text', hasMany: true },
|
||||
{ name: 'validatedAt', label: 'Validálás dátuma', type: 'date' },
|
||||
{ name: 'reportRef', label: 'Validációs riport (hivatkozás)', type: 'text' },
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { missingLegalValidation, validateLegalApproval } from './legal-validation'
|
||||
|
||||
const complete = { models: ['Claude Fable 5.1', 'Claude Opus 5.5'], validatedAt: '2026-09-29', reportRef: 'docs/legal-translation-validation.md' }
|
||||
|
||||
describe('legal approval rule (MITHOME-113)', () => {
|
||||
it('should accept a complete validation record', () => {
|
||||
expect(missingLegalValidation(complete)).toBeUndefined()
|
||||
expect(validateLegalApproval('approved', { siblingData: { legalValidation: complete } })).toBe(true)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ ...complete, models: ['Claude Opus 5.5'] }, 'validáló modell'],
|
||||
[{ ...complete, models: ['Claude Opus 5.5', ' Claude Opus 5.5 '] }, 'validáló modell'],
|
||||
[{ ...complete, validatedAt: null }, 'dátuma'],
|
||||
[{ ...complete, reportRef: ' ' }, 'riport'],
|
||||
[undefined, 'validáló modell'],
|
||||
])('should reject approval when the record is incomplete (%#)', (record, missing) => {
|
||||
const result = validateLegalApproval('approved', { siblingData: { legalValidation: record } })
|
||||
expect(result).toEqual(expect.stringContaining(missing))
|
||||
})
|
||||
|
||||
it.each(['none', 'ai-draft', undefined])('should not require a record for status %s', (status) => {
|
||||
expect(validateLegalApproval(status, { siblingData: {} })).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* MITHOME-113 (user decision): the English translation of a legal page may
|
||||
* only be approved after at least two independent high-capability models
|
||||
* reviewed it, with the date and the report recorded.
|
||||
*/
|
||||
export const MIN_VALIDATING_MODELS = 2
|
||||
|
||||
export type LegalValidationRecord = {
|
||||
models?: (string | null)[] | null
|
||||
validatedAt?: string | null
|
||||
reportRef?: string | null
|
||||
} | null | undefined
|
||||
|
||||
/** Returns what is missing from the record, or undefined when complete. */
|
||||
export function missingLegalValidation(record: LegalValidationRecord): string | undefined {
|
||||
const models = new Set((record?.models ?? []).map((m) => m?.trim()).filter(Boolean))
|
||||
const missing = [
|
||||
models.size < MIN_VALIDATING_MODELS && `legalább ${MIN_VALIDATING_MODELS} különböző validáló modell`,
|
||||
!record?.validatedAt && 'a validálás dátuma',
|
||||
!record?.reportRef?.trim() && 'a validációs riport hivatkozása',
|
||||
].filter(Boolean)
|
||||
return missing.length ? missing.join(', ') : undefined
|
||||
}
|
||||
|
||||
/** `validate` for the legal pages' enTranslationStatus field. */
|
||||
export function validateLegalApproval(value: unknown, { siblingData }: { siblingData?: { legalValidation?: LegalValidationRecord } }) {
|
||||
if (value !== 'approved') return true
|
||||
const missing = missingLegalValidation(siblingData?.legalValidation)
|
||||
return missing
|
||||
? `Jogi oldal angol fordítása csak többmodelles validáció után hagyható jóvá. Hiányzik: ${missing}.`
|
||||
: true
|
||||
}
|
||||
@@ -146,7 +146,8 @@ describe('Payload globals', () => {
|
||||
describe('MITHOME-111 localization rule', () => {
|
||||
// DECISION (design D1): structural values shared across locales.
|
||||
// MITHOME-112: `slug` is the shared URL identifier of LegalPages.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'address', 'slug'])
|
||||
// MITHOME-113: `models`/`reportRef` are legal-validation metadata, not copy.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'address', 'slug', 'models', 'reportRef'])
|
||||
|
||||
type Node = FieldLike & { localized?: boolean; fields?: Node[] }
|
||||
type Finding = { path: string; type?: string; localized: boolean }
|
||||
@@ -239,3 +240,21 @@ describe('MITHOME-113 English translation status', () => {
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe('MITHOME-113 legal validation gate', () => {
|
||||
type Validate = (value: unknown, opts: { siblingData: Record<string, unknown> }) => true | string
|
||||
const statusOf = (doc: { fields: unknown[] }) => findField(doc.fields, 'enTranslationStatus') as unknown as { validate?: Validate }
|
||||
|
||||
it('should block approving a legal page without a validation record', () => {
|
||||
expect(statusOf(LegalPages).validate?.('approved', { siblingData: {} })).toEqual(expect.any(String))
|
||||
expect(findField(LegalPages.fields, 'legalValidation')).toMatchObject({ type: 'group' })
|
||||
})
|
||||
|
||||
it.each([Home, About, Services, Contact, Common].map((g) => [g.slug, g] as const))(
|
||||
'should not add the legal rule to the %s global',
|
||||
(_slug, global) => {
|
||||
expect(statusOf(global).validate).toBeUndefined()
|
||||
expect(findField(global.fields, 'legalValidation')).toBeUndefined()
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user