feat(cms): align service claims with the real product range via migration (MITHOME-129)

The site promised more than the production server delivers (99.9%,
"nearly 100%", 1–100 GB SSD, unlimited traffic, 1–20 GB per mailbox,
Python/Node/PostgreSQL, DNSSEC, developer API, worldwide name servers,
immediate response). The 20260929_service_claims migration applies the
owner-confirmed texts C1–C14 (docs/termekkor-es-szerverkapacitas-
elemzes.md, ch. 9) and adds the 90% mailbox warning feature.

reviseContent() only replaces an exact Hungarian match, only rewrites
English that is still the old AI draft (human edits are kept and
reported), inserts list items once, and sends an approved page back to
ai-draft when its English changed. Published doc + latest version only.
Legal texts (terms, privacy) are left for legal review. The translation
memory gains the new pairs. Verified on a staging DB copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 16:03:46 +02:00
co-authored by Claude Opus 5.5
parent c468585ab9
commit d0dafa8471
7 changed files with 422 additions and 5 deletions
+105
View File
@@ -0,0 +1,105 @@
import { reviseContent, type ListInsertion, type TextRevision } from './content-revision'
import { collectLocalizedPaths } from './localize-paths'
type Doc = Record<string, unknown>
const FIELDS = [
{ name: 'title', type: 'text', localized: true },
{ name: 'items', type: 'array', localized: true, fields: [{ name: 'value', type: 'text' }] },
]
const PATHS = collectLocalizedPaths(FIELDS)
const REVISIONS: TextRevision[] = [
{ from: 'Régi cím', to: 'Új cím', enWas: 'Old title', enTo: 'New title' },
{ from: 'Régi elem', to: 'Új elem', enWas: 'Old item', enTo: 'New item' },
]
const INSERTIONS: ListInsertion[] = [{ afterHu: 'Új elem', hu: 'Beszúrt', afterEn: 'New item', en: 'Inserted' }]
let seq = 0
const newId = () => `id-${++seq}`
beforeEach(() => {
seq = 0
})
const doc = (): Doc => ({
title: { hu: 'Régi cím', en: 'Old title' },
items: {
hu: [{ value: 'Régi elem', id: 'h1' }, { value: 'Marad', id: 'h2' }],
en: [{ value: 'Old item', id: 'e1' }, { value: 'Stays', id: 'e2' }],
},
enTranslationStatus: 'ai-draft',
})
describe('reviseContent (MITHOME-129)', () => {
it('should replace exact Hungarian matches and their AI-draft English', () => {
const d = doc()
const report = reviseContent(d, PATHS, REVISIONS, [], newId)
expect(d.title).toEqual({ hu: 'Új cím', en: 'New title' })
expect(d.items).toEqual({
hu: [{ value: 'Új elem', id: 'h1' }, { value: 'Marad', id: 'h2' }],
en: [{ value: 'New item', id: 'e1' }, { value: 'Stays', id: 'e2' }],
})
expect(report).toEqual({ changed: 2, enKept: [] })
})
it('should leave text an editor already rewrote untouched', () => {
const d: Doc = { title: { hu: 'Szerkesztett cím', en: 'Edited title' } }
expect(reviseContent(d, PATHS, REVISIONS, [], newId)).toEqual({ changed: 0, enKept: [] })
expect(d.title).toEqual({ hu: 'Szerkesztett cím', en: 'Edited title' })
})
it('should keep and report a human English edit', () => {
const d: Doc = { title: { hu: 'Régi cím', en: 'Human title' } }
const report = reviseContent(d, PATHS, REVISIONS, [], newId)
expect(d.title).toEqual({ hu: 'Új cím', en: 'Human title' })
expect(report.enKept).toEqual(['Régi cím'])
})
it('should report a list item whose English row was edited by a person', () => {
const d = doc()
;(d.items as { en: { value: string }[] }).en[0].value = 'Human item'
const report = reviseContent(d, PATHS, REVISIONS, [], newId)
expect(report.enKept).toEqual(['Régi elem'])
expect((d.items as { en: { value: string }[] }).en[0].value).toBe('Human item')
})
it('should fill an empty English value', () => {
const d: Doc = { title: { hu: 'Régi cím' } }
reviseContent(d, PATHS, REVISIONS, [], newId)
expect(d.title).toEqual({ hu: 'Új cím', en: 'New title' })
})
it('should insert a list item after its anchor in both languages, once', () => {
const d = doc()
reviseContent(d, PATHS, REVISIONS, INSERTIONS, newId)
reviseContent(d, PATHS, REVISIONS, INSERTIONS, newId)
const items = d.items as { hu: { value: string }[]; en: { value: string }[] }
expect(items.hu.map((r) => r.value)).toEqual(['Új elem', 'Beszúrt', 'Marad'])
expect(items.en.map((r) => r.value)).toEqual(['New item', 'Inserted', 'Stays'])
})
it('should be idempotent', () => {
const d = doc()
reviseContent(d, PATHS, REVISIONS, INSERTIONS, newId)
const snapshot = JSON.stringify(d)
expect(reviseContent(d, PATHS, REVISIONS, INSERTIONS, newId)).toEqual({ changed: 0, enKept: [] })
expect(JSON.stringify(d)).toBe(snapshot)
})
it('should send an approved page back to AI draft when its English changed', () => {
const d = { ...doc(), enTranslationStatus: 'approved' }
reviseContent(d, PATHS, REVISIONS, [], newId)
expect(d.enTranslationStatus).toBe('ai-draft')
})
it('should keep an approved status when only Hungarian changed', () => {
const d: Doc = { title: { hu: 'Régi cím', en: 'Human title' }, enTranslationStatus: 'approved' }
reviseContent(d, PATHS, REVISIONS, [], newId)
expect(d.enTranslationStatus).toBe('approved')
})
it('should ignore legacy unwrapped values and lists without an anchor', () => {
const d: Doc = { title: 'Régi cím', items: { hu: [{ value: 'Más', id: 'x' }] } }
expect(reviseContent(d, PATHS, REVISIONS, INSERTIONS, newId)).toEqual({ changed: 0, enKept: [] })
})
})
+96
View File
@@ -0,0 +1,96 @@
/**
* MITHOME-129: exact-match content revision on localized fields, in place.
*
* Used by data migrations that correct published copy (e.g. service claims
* aligned with the real product range). Rules:
* - a value changes only when its current Hungarian text is EXACTLY the
* expected old text — anything an editor already rewrote is left alone;
* - English is replaced only when it is empty or still the old AI draft
* (`enWas`) — a human English edit is kept and reported instead;
* - if English changed on a page whose translation was approved, the page
* goes back to "ai-draft": the new English has not been reviewed yet.
* Works for localized text leaves and whole-array localized string lists
* ({ value } rows), where it can also insert a new item after an anchor.
*/
import { applyAll, isPlainObject, type LocalizedPath } from './localize-paths'
export type TextRevision = { from: string; to: string; enWas?: string; enTo: string }
export type ListInsertion = { afterHu: string; hu: string; afterEn: string; en: string }
export type RevisionReport = { changed: number; enKept: string[] }
type Row = { value?: unknown; id?: unknown }
const isEmpty = (value: unknown) => value === undefined || value === null || value === ''
function reviseText(value: Record<string, unknown>, revisions: readonly TextRevision[], report: RevisionReport) {
const revision = revisions.find((r) => r.from === value.hu)
if (!revision) return { hu: false, en: false }
value.hu = revision.to
if (isEmpty(value.en) || value.en === revision.enWas) {
value.en = revision.enTo
return { hu: true, en: true }
}
report.enKept.push(revision.from)
return { hu: true, en: false }
}
function reviseRows(rows: Row[], match: (text: string) => string | undefined): number {
let count = 0
for (const row of rows) {
const next = typeof row.value === 'string' ? match(row.value) : undefined
if (next !== undefined) {
row.value = next
count += 1
}
}
return count
}
function insertRow(rows: Row[], after: string, text: string, newId: () => string): boolean {
if (rows.some((row) => row.value === text)) return false
const index = rows.findIndex((row) => row.value === after)
if (index === -1) return false
rows.splice(index + 1, 0, { value: text, id: newId() })
return true
}
export function reviseContent(
doc: Record<string, unknown>,
paths: readonly LocalizedPath[],
revisions: readonly TextRevision[],
insertions: readonly ListInsertion[],
newId: () => string,
): RevisionReport {
const report: RevisionReport = { changed: 0, enKept: [] }
let enChanged = false
applyAll(doc, paths, (value) => {
if (!isPlainObject(value)) return { value, changed: false }
if (typeof value.hu === 'string') {
const result = reviseText(value, revisions, report)
enChanged ||= result.en
if (result.hu) report.changed += 1
return { value, changed: result.hu }
}
if (!Array.isArray(value.hu)) return { value, changed: false }
const hu = value.hu as Row[]
const en = Array.isArray(value.en) ? (value.en as Row[]) : undefined
const huMatched = revisions.filter((r) => hu.some((row) => row.value === r.from))
let count = reviseRows(hu, (text) => revisions.find((r) => r.from === text)?.to)
const enCount = en ? reviseRows(en, (text) => revisions.find((r) => r.enWas !== undefined && r.enWas === text)?.enTo) : 0
// A Hungarian row changed but its English row was not the old AI draft.
if (en && enCount < huMatched.length) report.enKept.push(...huMatched.map((r) => r.from).slice(enCount))
for (const insertion of insertions) {
if (insertRow(hu, insertion.afterHu, insertion.hu, newId)) count += 1
if (en && insertRow(en, insertion.afterEn, insertion.en, newId)) enChanged = true
}
enChanged ||= enCount > 0
report.changed += count
return { value, changed: count > 0 || enCount > 0 }
})
if (enChanged && doc.enTranslationStatus === 'approved') doc.enTranslationStatus = 'ai-draft'
return report
}