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:
Do Siki
2026-09-29 11:19:54 +02:00
co-authored by Claude Opus 5.5
parent acd1ff2ed9
commit bff08edafe
12 changed files with 190 additions and 96 deletions
+36 -15
View File
@@ -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([])
})
})
+33 -19
View File
@@ -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}.`
)
}
+9
View File
@@ -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"')
})
+8 -1
View File
@@ -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) {