feat(cms): record hand-run legal translation reviews in the CMS (MITHOME-113)
Validation of legal translations is a manual flow (user decision): copy the prompt, run it in any vendor's model, paste the answer back. The legal validation block now holds the prompt panel and a list of reviews (model, date, verdict, pasted answer, notes) instead of a model list and report link. Approval needs two distinct models whose latest complete review does not reject; a newer review supersedes a model's rejection. The locale path collector now looks through row/collapsible wrappers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
acd1ff2ed9
commit
bff08edafe
@@ -3,6 +3,7 @@ import type { CollectionConfig } from 'payload'
|
||||
import { collectionVersions } from '../lib/payload-versions'
|
||||
import { translationStatusField } from '../globals/fields/translationStatus'
|
||||
import { validateLegalApproval } from '../lib/legal-validation'
|
||||
import { legalValidationGroup } from './fields/legalValidation'
|
||||
|
||||
/**
|
||||
* Mirrors LegalPageContent (proto/src/content/types.ts) — MITHOME-88.
|
||||
@@ -60,30 +61,6 @@ export const LegalPages: CollectionConfig = {
|
||||
// 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' },
|
||||
],
|
||||
},
|
||||
{
|
||||
// MITHOME-113 (D8): copyable review prompt built from the saved hu + en texts.
|
||||
name: 'validationPrompt',
|
||||
type: 'ui',
|
||||
admin: {
|
||||
position: 'sidebar',
|
||||
components: { Field: './src/components/admin/LegalValidationPrompt#LegalValidationPrompt' },
|
||||
},
|
||||
},
|
||||
legalValidationGroup,
|
||||
],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import type { GroupField } from 'payload'
|
||||
|
||||
import { REVIEW_VERDICTS, type ReviewVerdict } from '../../lib/legal-validation'
|
||||
|
||||
const VERDICT_LABELS: Record<ReviewVerdict, string> = {
|
||||
approve: 'Jóváhagyható',
|
||||
'approve-with-changes': 'Javításokkal jóváhagyható',
|
||||
reject: 'Elutasítva',
|
||||
}
|
||||
|
||||
/**
|
||||
* MITHOME-113 (design D7/D8): legal translation validation block — the
|
||||
* copyable prompt panel, then one row per model review with the pasted
|
||||
* answer. Shared across locales: it is metadata about the English text.
|
||||
*/
|
||||
export const legalValidationGroup: GroupField = {
|
||||
name: 'legalValidation',
|
||||
label: 'Jogi validáció (angol fordítás)',
|
||||
type: 'group',
|
||||
admin: {
|
||||
description:
|
||||
'1. Másold ki a promptot, és futtasd le egy magas szintű modellben. 2. A választ rögzítsd új validálásként. ' +
|
||||
'Jóváhagyáshoz legalább két különböző modell el nem utasító validálása kell (modellenként a legutóbbi számít). ' +
|
||||
'A modell-validáció nem helyettesíti a jogi szakvéleményt.',
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'validationPrompt',
|
||||
type: 'ui',
|
||||
admin: { components: { Field: './src/components/admin/LegalValidationPrompt#LegalValidationPrompt' } },
|
||||
},
|
||||
{
|
||||
name: 'reviews',
|
||||
label: 'Validálások',
|
||||
labels: { singular: 'Validálás', plural: 'Validálások' },
|
||||
type: 'array',
|
||||
fields: [
|
||||
{
|
||||
type: 'row',
|
||||
fields: [
|
||||
{ name: 'model', label: 'Modell (pl. Claude Opus 5.5, GPT-5, Gemini)', type: 'text', required: true },
|
||||
{ name: 'reviewedAt', label: 'Dátum', type: 'date', required: true },
|
||||
{
|
||||
name: 'verdict',
|
||||
label: 'Ítélet',
|
||||
type: 'select',
|
||||
required: true,
|
||||
options: REVIEW_VERDICTS.map((value) => ({ label: VERDICT_LABELS[value], value })),
|
||||
},
|
||||
],
|
||||
},
|
||||
{ name: 'result', label: 'A modell válasza (beillesztve)', type: 'textarea', required: true },
|
||||
{ name: 'notes', label: 'Megjegyzés, meghozott döntések', type: 'textarea' },
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { buildLegalValidationPrompt, type LegalText } from '@/lib/legal-validati
|
||||
|
||||
/**
|
||||
* MITHOME-113 (design D8) — "Validation prompt" panel in the legal page
|
||||
* editor sidebar: a ready-to-copy prompt for reviewing the English
|
||||
* editor's legal validation block (above the pasted review entries): a ready-to-copy prompt for reviewing the English
|
||||
* translation with a high-capability model. The prompt comes from the same
|
||||
* template the project's own validation uses (src/lib/legal-validation-prompt.ts).
|
||||
*
|
||||
@@ -76,8 +76,8 @@ export function LegalValidationPrompt() {
|
||||
<div className="field-type" style={{ marginBottom: 'var(--base)' }}>
|
||||
<label className="field-label">Validációs prompt (angol fordítás)</label>
|
||||
<p style={{ color: 'var(--theme-elevation-500)', fontSize: '0.8rem', margin: '0 0 0.5rem' }}>
|
||||
Másold be egy magas szintű modellbe (legalább kettőbe, egymástól függetlenül), majd rögzítsd az eredményt a
|
||||
„Jogi validáció” mezőkben. A prompt a legutóbb mentett változatból készül.
|
||||
Másold be egy magas szintű modellbe (legalább kettőbe, egymástól függetlenül), majd a választ rögzítsd alább,
|
||||
új validálásként. A prompt a legutóbb mentett változatból készül.
|
||||
</p>
|
||||
{state.kind === 'loading' && <p>Betöltés…</p>}
|
||||
{state.kind === 'unsaved' && <p>Előbb mentsd el a dokumentumot.</p>}
|
||||
|
||||
@@ -1,25 +1,46 @@
|
||||
import { missingLegalValidation, validateLegalApproval } from './legal-validation'
|
||||
import { acceptingModels, 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' }
|
||||
const review = (model: string, verdict = 'approve', reviewedAt = '2026-09-29', result = '| Section | … |') => ({
|
||||
model,
|
||||
verdict,
|
||||
reviewedAt,
|
||||
result,
|
||||
})
|
||||
const approve = (reviews: ReturnType<typeof review>[]) =>
|
||||
validateLegalApproval('approved', { siblingData: { legalValidation: { reviews } } })
|
||||
|
||||
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('should accept two distinct models with complete, non-rejecting reviews', () => {
|
||||
expect(approve([review('Claude Opus 5.5'), review('GPT-5', 'approve-with-changes')])).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('should not count the same model twice (case- and space-insensitive)', () => {
|
||||
expect(approve([review('Claude Opus 5.5'), review(' claude opus 5.5 ')])).toEqual(expect.stringContaining('Jelenleg: 1'))
|
||||
})
|
||||
|
||||
it.each(['none', 'ai-draft', undefined])('should not require a record for status %s', (status) => {
|
||||
it('should ignore incomplete reviews (no pasted answer)', () => {
|
||||
expect(approve([review('Claude Opus 5.5'), review('GPT-5', 'approve', '2026-09-29', ' ')])).toEqual(expect.any(String))
|
||||
})
|
||||
|
||||
it('should not count a model whose latest verdict is reject', () => {
|
||||
expect(approve([review('Claude Opus 5.5'), review('GPT-5', 'reject')])).toEqual(expect.any(String))
|
||||
})
|
||||
|
||||
it('should let a newer review of the same model supersede its rejection', () => {
|
||||
const reviews = [review('GPT-5', 'reject', '2026-09-28'), review('GPT-5', 'approve', '2026-09-30'), review('Claude Opus 5.5')]
|
||||
expect(acceptingModels({ reviews })).toEqual(['GPT-5', 'Claude Opus 5.5'])
|
||||
expect(approve(reviews)).toBe(true)
|
||||
})
|
||||
|
||||
it('should keep an older approval superseded by a newer rejection out', () => {
|
||||
expect(acceptingModels({ reviews: [review('GPT-5', 'approve', '2026-09-28'), review('GPT-5', 'reject', '2026-09-30')] })).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['none', 'ai-draft', undefined])('should not require reviews for status %s', (status) => {
|
||||
expect(validateLegalApproval(status, { siblingData: {} })).toBe(true)
|
||||
})
|
||||
|
||||
it('should handle a missing record', () => {
|
||||
expect(acceptingModels(undefined)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,32 +1,46 @@
|
||||
/**
|
||||
* 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.
|
||||
* reviewed it. Reviews are run by hand with the admin's copyable prompt
|
||||
* (any model vendor) and their answers are pasted back into the CMS.
|
||||
*
|
||||
* DECISION: per model only its LATEST review counts — a rejection can be
|
||||
* superseded by re-running the same model on the corrected translation —
|
||||
* and a model whose latest verdict is "reject" does not count.
|
||||
*/
|
||||
export const MIN_VALIDATING_MODELS = 2
|
||||
|
||||
export type LegalValidationRecord = {
|
||||
models?: (string | null)[] | null
|
||||
validatedAt?: string | null
|
||||
reportRef?: string | null
|
||||
} | null | undefined
|
||||
export const REVIEW_VERDICTS = ['approve', 'approve-with-changes', 'reject'] as const
|
||||
export type ReviewVerdict = (typeof REVIEW_VERDICTS)[number]
|
||||
|
||||
/** 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
|
||||
export type LegalReview = {
|
||||
model?: string | null
|
||||
reviewedAt?: string | null
|
||||
verdict?: string | null
|
||||
result?: string | null
|
||||
}
|
||||
export type LegalValidationRecord = { reviews?: LegalReview[] | null } | null | undefined
|
||||
|
||||
const isComplete = (r: LegalReview) => Boolean(r.model?.trim() && r.reviewedAt && r.verdict && r.result?.trim())
|
||||
const modelKey = (r: LegalReview) => r.model!.trim().toLowerCase()
|
||||
|
||||
/** Distinct models whose latest complete review does not reject the translation. */
|
||||
export function acceptingModels(record: LegalValidationRecord): string[] {
|
||||
const latest = new Map<string, LegalReview>()
|
||||
for (const review of (record?.reviews ?? []).filter(isComplete)) {
|
||||
const current = latest.get(modelKey(review))
|
||||
if (!current || review.reviewedAt! >= current.reviewedAt!) latest.set(modelKey(review), review)
|
||||
}
|
||||
return [...latest.values()].filter((r) => r.verdict !== 'reject').map((r) => r.model!.trim())
|
||||
}
|
||||
|
||||
/** `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
|
||||
const accepted = acceptingModels(siblingData?.legalValidation)
|
||||
if (accepted.length >= MIN_VALIDATING_MODELS) return true
|
||||
return (
|
||||
`Jogi oldal angol fordítása csak legalább ${MIN_VALIDATING_MODELS} különböző modell el nem utasító, ` +
|
||||
`teljes (modell, dátum, ítélet, válasz) validálása után hagyható jóvá. Jelenleg: ${accepted.length}.`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -48,6 +48,15 @@ describe('collectLocalizedPaths', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('should look through unnamed row/collapsible wrappers', () => {
|
||||
expect(
|
||||
collectLocalizedPaths([
|
||||
{ name: 'g', type: 'group', fields: [{ type: 'row', fields: [{ name: 't', type: 'text', localized: true }] }] },
|
||||
{ type: 'collapsible', fields: [{ name: 'u', type: 'text', localized: true }] },
|
||||
]),
|
||||
).toEqual([['g', 't'], ['u']])
|
||||
})
|
||||
|
||||
it('should throw on layout fields that could hide localized data', () => {
|
||||
expect(() => collectLocalizedPaths([{ type: 'tabs' }])).toThrow('unsupported field type "tabs"')
|
||||
})
|
||||
|
||||
@@ -19,7 +19,10 @@ export type LocalizedPath = readonly string[]
|
||||
const ARRAY_ROWS = '[]'
|
||||
|
||||
/** Layout fields that could hide localized children — not traversed here. */
|
||||
const UNSUPPORTED_CONTAINERS = new Set(['tabs', 'row', 'collapsible', 'blocks'])
|
||||
const UNSUPPORTED_CONTAINERS = new Set(['tabs', 'blocks'])
|
||||
|
||||
/** Unnamed layout wrappers: their children are stored at the same level. */
|
||||
const TRANSPARENT_CONTAINERS = new Set(['row', 'collapsible'])
|
||||
|
||||
export function collectLocalizedPaths(
|
||||
fields: readonly FieldNode[],
|
||||
@@ -31,6 +34,10 @@ export function collectLocalizedPaths(
|
||||
// DECISION: fail fast rather than silently skip localized data.
|
||||
throw new Error(`collectLocalizedPaths: unsupported field type "${field.type}"`)
|
||||
}
|
||||
if (TRANSPARENT_CONTAINERS.has(field.type)) {
|
||||
paths.push(...collectLocalizedPaths(field.fields ?? [], prefix))
|
||||
continue
|
||||
}
|
||||
if (!field.name) continue
|
||||
const path = [...prefix, field.name]
|
||||
if (field.localized) {
|
||||
|
||||
@@ -146,8 +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.
|
||||
// MITHOME-113: `models`/`reportRef` are legal-validation metadata, not copy.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'address', 'slug', 'models', 'reportRef'])
|
||||
// MITHOME-113: `result`/`notes` are legal-validation metadata, not copy.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'address', 'slug', 'result', 'notes'])
|
||||
|
||||
type Node = FieldLike & { localized?: boolean; fields?: Node[] }
|
||||
type Finding = { path: string; type?: string; localized: boolean }
|
||||
|
||||
Reference in New Issue
Block a user