Compare commits
3
Commits
c1be3a586b
...
8687ae28a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8687ae28a2 | ||
|
|
477b1a9b78 | ||
|
|
a6f7b07a69 |
@@ -66,6 +66,7 @@ Next.js 15 alapú weboldal a mozdIT Bt. számára, Docker Compose-szal deployolv
|
|||||||
| MITHOME-98 | Bug: dev docker-compose MongoDB URI nem hitelesített (auth hiányzott) | ✅ |
|
| MITHOME-98 | Bug: dev docker-compose MongoDB URI nem hitelesített (auth hiányzott) | ✅ |
|
||||||
| MITHOME-17 | Winston structured app logging to stdout/stderr | ✅ |
|
| MITHOME-17 | Winston structured app logging to stdout/stderr | ✅ |
|
||||||
| MITHOME-33 | Bug: staging és production Loki host-ra hivatkozik Loki service nélkül | ✅ |
|
| MITHOME-33 | Bug: staging és production Loki host-ra hivatkozik Loki service nélkül | ✅ |
|
||||||
|
| MITHOME-126 | Bug: logger graceful shutdown `write after end` a `npm run build` alatt | ✅ |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -211,6 +212,7 @@ docker-compose -f docker-compose.dev.yml down
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Frissítési Napló
|
## Frissítési Napló
|
||||||
|
- **2026-09-29**: MITHOME-126 (bug: `write after end` a build alatt) kész. Gyökérok: a `logger.ts` SIGTERM/SIGINT kezelője minden modul-kiértékeléskor újra regisztrálódott, és ha egy build worker mindkét jelet megkapta, a második hívás a már lezárt (`logger.end()`) Winston streamre logolt. A `logger.writableEnded` guardként nem működik, mert a winston Logger `readable-stream@3` Transform, amiben ez a property nincs. Javítás: saját `hasShutdownStarted` flag, a kezelők processzenként egyszer, `process.once`-szal regisztrálódnak. Felfedező + megőrző tesztek a `logger.test.ts`-ben (fix-bug workflow); `npm test`, lint, `tsc --noEmit` zöld, 3 egymás utáni buildben nincs `write after end`.
|
||||||
- **2026-09-29**: MITHOME-112 + MITHOME-113 kiadva stagingre (`b3331d5`). Mentés deploy előtt: `~/backups/mozdit-staging-20260929-120203-pre-mithome-112-113.archive`. Induláskor lefutott a legal-pages lokalizáció (72 érték) és az angol AI-draft import (324 érték, 0 egyezés nélküli). 8/8 staging smoke zöld; a `/hu` változatlan, az `/en` jóváhagyásig magyar. Az adminban minden oldal „AI-draft, átnézésre vár” állapotban van.
|
- **2026-09-29**: MITHOME-112 + MITHOME-113 kiadva stagingre (`b3331d5`). Mentés deploy előtt: `~/backups/mozdit-staging-20260929-120203-pre-mithome-112-113.archive`. Induláskor lefutott a legal-pages lokalizáció (72 érték) és az angol AI-draft import (324 érték, 0 egyezés nélküli). 8/8 staging smoke zöld; a `/hu` változatlan, az `/en` jóváhagyásig magyar. Az adminban minden oldal „AI-draft, átnézésre vár” állapotban van.
|
||||||
- **2026-09-29**: MITHOME-112 + MITHOME-113 kész (main, staging deploy még nem történt), OpenSpec: `openspec/changes/english-content-mithome-112-113`. A LegalPages lokalizált (migrációval). Minden Global és jogi oldal „Angol fordítás állapota” mezőt kapott (Nincs / AI-draft / Jóváhagyva); a publikus `/en` csak jóváhagyás után mutat angolt. Az AI-draft angol tartalom (179 szöveg az élő staging tartalomból, `src/content/translations/en.json`) migrációval kerül be, csak üres angol mezőbe és pontos magyar egyezésnél. A jogi oldalakon „Jogi validáció” blokk: másolható validációs prompt és a kézzel futtatott modellek visszaírt válaszai; a jóváhagyáshoz legalább két különböző modell el nem utasító validálása kell (felhasználói döntés: a validálást kézzel végzik, bármely szolgáltató modelljével). Staging-másolaton ellenőrizve (324 angol érték, 0 egyezés nélküli; a `/hu` szövegre azonos). Élő teszt közben talált és javított hiba: a vágólap-másolás tartalék lánccal. Mellékmegfigyelés: `npm run build` alatt a logger leállítási kezelője `write after end` hibát ír (`logger.ts`, MITHOME-17), a build ettől sikeres.
|
- **2026-09-29**: MITHOME-112 + MITHOME-113 kész (main, staging deploy még nem történt), OpenSpec: `openspec/changes/english-content-mithome-112-113`. A LegalPages lokalizált (migrációval). Minden Global és jogi oldal „Angol fordítás állapota” mezőt kapott (Nincs / AI-draft / Jóváhagyva); a publikus `/en` csak jóváhagyás után mutat angolt. Az AI-draft angol tartalom (179 szöveg az élő staging tartalomból, `src/content/translations/en.json`) migrációval kerül be, csak üres angol mezőbe és pontos magyar egyezésnél. A jogi oldalakon „Jogi validáció” blokk: másolható validációs prompt és a kézzel futtatott modellek visszaírt válaszai; a jóváhagyáshoz legalább két különböző modell el nem utasító validálása kell (felhasználói döntés: a validálást kézzel végzik, bármely szolgáltató modelljével). Staging-másolaton ellenőrizve (324 angol érték, 0 egyezés nélküli; a `/hu` szövegre azonos). Élő teszt közben talált és javított hiba: a vágólap-másolás tartalék lánccal. Mellékmegfigyelés: `npm run build` alatt a logger leállítási kezelője `write after end` hibát ír (`logger.ts`, MITHOME-17), a build ettől sikeres.
|
||||||
- **2026-09-29**: MITHOME-112 + MITHOME-113 tervezés kész, megvalósításra vár: `openspec/changes/english-content-mithome-112-113`. Döntések: előbb a LegalPages lokalizálása; nem lokalizált „Angol fordítás állapota” mező + kapu (az `/en` jóváhagyásig magyart mutat); a forrás az élő staging tartalom, repóban tárolt magyar → angol szótárral; a jogi szövegek angol fordítását kötelező legalább két magas szintű modellel validálni (a CMS validációs rekord nélkül nem engedi jóváhagyni), a jogi oldal szerkesztőjében másolható validációs segédprompttal. Közben felvéve: MITHOME-125 (opcionális Chat funkció, backlog).
|
- **2026-09-29**: MITHOME-112 + MITHOME-113 tervezés kész, megvalósításra vár: `openspec/changes/english-content-mithome-112-113`. Döntések: előbb a LegalPages lokalizálása; nem lokalizált „Angol fordítás állapota” mező + kapu (az `/en` jóváhagyásig magyart mutat); a forrás az élő staging tartalom, repóban tárolt magyar → angol szótárral; a jogi szövegek angol fordítását kötelező legalább két magas szintű modellel validálni (a CMS validációs rekord nélkül nem engedi jóváhagyni), a jogi oldal szerkesztőjében másolható validációs segédprompttal. Közben felvéve: MITHOME-125 (opcionális Chat funkció, backlog).
|
||||||
|
|||||||
@@ -134,6 +134,113 @@ without a manual step.
|
|||||||
- **WHEN** the migration is executed on already migrated data
|
- **WHEN** the migration is executed on already migrated data
|
||||||
- **THEN** stored values SHALL remain unchanged
|
- **THEN** stored values SHALL remain unchanged
|
||||||
|
|
||||||
|
### Requirement: Localized legal pages
|
||||||
|
|
||||||
|
Legal pages SHALL store their title, last-updated text, and section titles and
|
||||||
|
contents separately per locale. The slug and section identifiers SHALL be shared across
|
||||||
|
locales. Existing Hungarian legal content SHALL be preserved as the Hungarian value,
|
||||||
|
including published content and version history.
|
||||||
|
|
||||||
|
#### Scenario: An administrator adds an English privacy policy
|
||||||
|
|
||||||
|
- **WHEN** an administrator edits a legal page in the `en` locale
|
||||||
|
- **THEN** the Hungarian legal page content SHALL remain unchanged
|
||||||
|
|
||||||
|
#### Scenario: Existing legal page after migration
|
||||||
|
|
||||||
|
- **WHEN** the localized legal page configuration is deployed onto existing data
|
||||||
|
- **THEN** the Hungarian legal pages SHALL render the same content as before
|
||||||
|
|
||||||
|
### Requirement: English translation status
|
||||||
|
|
||||||
|
Every page global and legal page SHALL carry an English translation status with the
|
||||||
|
values "no translation", "AI draft awaiting review", and "approved", visible to
|
||||||
|
administrators with a warning that AI drafts require review. Only an administrator
|
||||||
|
action SHALL set the status to "approved".
|
||||||
|
|
||||||
|
#### Scenario: AI draft is imported
|
||||||
|
|
||||||
|
- **WHEN** machine-translated English content is imported for a page
|
||||||
|
- **THEN** that page's status SHALL be "AI draft awaiting review"
|
||||||
|
|
||||||
|
#### Scenario: An administrator approves a translation
|
||||||
|
|
||||||
|
- **WHEN** an administrator sets the status to "approved" and publishes
|
||||||
|
- **THEN** the page SHALL be marked as having an approved English translation
|
||||||
|
|
||||||
|
### Requirement: Non-destructive AI draft import
|
||||||
|
|
||||||
|
Importing AI-draft English content SHALL only fill English values that are empty and
|
||||||
|
whose current Hungarian source text is identical to the text that was translated. It
|
||||||
|
SHALL NOT change Hungarian values, shared values, or existing English values, SHALL
|
||||||
|
keep placeholders such as `{year}`, `{min}` and `{privacyHref}` intact, and SHALL be
|
||||||
|
safe to run more than once.
|
||||||
|
|
||||||
|
#### Scenario: Hungarian text changed after translation
|
||||||
|
|
||||||
|
- **WHEN** a Hungarian value differs from the source text in the translation memory
|
||||||
|
- **THEN** its English value SHALL stay empty and the import SHALL report it
|
||||||
|
|
||||||
|
#### Scenario: An English value was already edited by a person
|
||||||
|
|
||||||
|
- **WHEN** a field already has an English value
|
||||||
|
- **THEN** the import SHALL leave it unchanged
|
||||||
|
|
||||||
|
### Requirement: Validated English legal pages
|
||||||
|
|
||||||
|
The English translation of a legal page SHALL NOT be set to "approved" unless at least
|
||||||
|
two distinct language models have reviewed it and their reviews are recorded in the CMS.
|
||||||
|
Each review record SHALL contain the model name, the review date, the verdict (approve,
|
||||||
|
approve with changes, reject), and the model's pasted answer. For each model only its
|
||||||
|
latest review SHALL count, and a model whose latest verdict is "reject" SHALL NOT count.
|
||||||
|
Reviews SHALL be run with the admin validation prompt, which covers meaning equivalence
|
||||||
|
with the Hungarian text, data-protection terminology, omissions or additions, and
|
||||||
|
preserved placeholders.
|
||||||
|
|
||||||
|
#### Scenario: Approving an unvalidated legal translation
|
||||||
|
|
||||||
|
- **WHEN** an administrator sets a legal page's English status to "approved" while fewer
|
||||||
|
than two distinct models have a complete, non-rejecting latest review
|
||||||
|
- **THEN** the CMS SHALL reject the save with a validation error
|
||||||
|
|
||||||
|
#### Scenario: Approving a validated legal translation
|
||||||
|
|
||||||
|
- **WHEN** two distinct models each have a complete latest review that does not reject
|
||||||
|
the translation
|
||||||
|
- **THEN** the CMS SHALL allow the status to be set to "approved"
|
||||||
|
|
||||||
|
#### Scenario: A rejection is superseded
|
||||||
|
|
||||||
|
- **WHEN** a model rejected the translation and, after corrections, a newer review by the
|
||||||
|
same model approves it
|
||||||
|
- **THEN** that model SHALL count towards the required reviews
|
||||||
|
|
||||||
|
#### Scenario: Page globals are not affected
|
||||||
|
|
||||||
|
- **WHEN** an administrator approves the English translation of a page global
|
||||||
|
- **THEN** no legal validation record SHALL be required
|
||||||
|
|
||||||
|
### Requirement: Legal validation prompt in the admin
|
||||||
|
|
||||||
|
The legal page editor SHALL offer administrators a ready-to-use validation prompt for
|
||||||
|
the English translation. The prompt SHALL contain the review criteria, the requested
|
||||||
|
structured output format, and the current Hungarian and English text of every section
|
||||||
|
of that page, and SHALL be copyable with a single action. The prompt SHALL be generated
|
||||||
|
from the same template that is used for the project's own model validation.
|
||||||
|
|
||||||
|
#### Scenario: An administrator copies the validation prompt
|
||||||
|
|
||||||
|
- **WHEN** an administrator opens a legal page that has English content and uses the
|
||||||
|
copy action of the validation prompt panel
|
||||||
|
- **THEN** the clipboard SHALL contain a prompt with the review criteria and the
|
||||||
|
Hungarian and English text of each section of the current version
|
||||||
|
|
||||||
|
#### Scenario: No English text yet
|
||||||
|
|
||||||
|
- **WHEN** a legal page has no English content
|
||||||
|
- **THEN** the panel SHALL state that there is nothing to validate instead of offering
|
||||||
|
a prompt
|
||||||
|
|
||||||
### Requirement: Public partner media
|
### Requirement: Public partner media
|
||||||
|
|
||||||
The CMS SHALL allow authenticated administrators to manage partner records and image
|
The CMS SHALL allow authenticated administrators to manage partner records and image
|
||||||
|
|||||||
@@ -63,3 +63,23 @@ metadata for the requested locale where page metadata is available.
|
|||||||
- **WHEN** metadata is generated for a supported page and locale
|
- **WHEN** metadata is generated for a supported page and locale
|
||||||
- **THEN** its title and description SHALL use that locale's page content or configured
|
- **THEN** its title and description SHALL use that locale's page content or configured
|
||||||
localized fallback text
|
localized fallback text
|
||||||
|
|
||||||
|
### Requirement: Approved English content only
|
||||||
|
|
||||||
|
An English public page SHALL render its English content only when that page's English
|
||||||
|
translation status is "approved". Otherwise it SHALL render the Hungarian content of the
|
||||||
|
same page. Routing, navigation labels, and shared values SHALL be unaffected by the
|
||||||
|
status.
|
||||||
|
|
||||||
|
#### Scenario: English translation is an unapproved AI draft
|
||||||
|
|
||||||
|
- **WHEN** a visitor opens an English page whose translation status is "AI draft
|
||||||
|
awaiting review"
|
||||||
|
- **THEN** the page SHALL render the Hungarian content
|
||||||
|
|
||||||
|
#### Scenario: English translation is approved
|
||||||
|
|
||||||
|
- **WHEN** a visitor opens an English page whose translation status is "approved" and
|
||||||
|
the page is published
|
||||||
|
- **THEN** the page SHALL render the English values, falling back to Hungarian for any
|
||||||
|
field without an English value
|
||||||
|
|||||||
@@ -196,3 +196,75 @@ describe('Logger', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Logger graceful shutdown', () => {
|
||||||
|
const SIGNALS = ['SIGTERM', 'SIGINT'] as const
|
||||||
|
const HANDLERS_KEY = Symbol.for('mozdit.logger.shutdownHandlersRegistered')
|
||||||
|
const processState = process as unknown as Record<symbol, unknown>
|
||||||
|
type Signal = typeof SIGNALS[number]
|
||||||
|
let baseline: Record<Signal, NodeJS.SignalsListener[]>
|
||||||
|
|
||||||
|
const addedListeners = (signal: Signal) =>
|
||||||
|
process.listeners(signal).filter((listener) => !baseline[signal].includes(listener)) as NodeJS.SignalsListener[]
|
||||||
|
|
||||||
|
const loadLogger = () => {
|
||||||
|
const { logger } = require('./logger')
|
||||||
|
// WHY: plain mock — winston's readable-stream@3 Logger exposes no `writableEnded` after end()
|
||||||
|
logger.end = jest.fn()
|
||||||
|
return logger
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules()
|
||||||
|
delete processState[HANDLERS_KEY]
|
||||||
|
baseline = { SIGTERM: process.listeners('SIGTERM'), SIGINT: process.listeners('SIGINT') }
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const signal of SIGNALS) {
|
||||||
|
addedListeners(signal).forEach((listener) => process.removeListener(signal, listener))
|
||||||
|
}
|
||||||
|
delete processState[HANDLERS_KEY]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Exploration: fails on the pre-fix code (MITHOME-126)
|
||||||
|
it('should not write the shutdown message again after the logger has ended', () => {
|
||||||
|
const logger = loadLogger()
|
||||||
|
const [onSigterm] = addedListeners('SIGTERM')
|
||||||
|
const [onSigint] = addedListeners('SIGINT')
|
||||||
|
|
||||||
|
onSigterm('SIGTERM')
|
||||||
|
onSigint('SIGINT')
|
||||||
|
|
||||||
|
expect(logger.info).toHaveBeenCalledTimes(1)
|
||||||
|
expect(logger.end).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should register the shutdown handlers only once per process', () => {
|
||||||
|
loadLogger()
|
||||||
|
jest.resetModules()
|
||||||
|
loadLogger()
|
||||||
|
|
||||||
|
expect(addedListeners('SIGTERM')).toHaveLength(1)
|
||||||
|
expect(addedListeners('SIGINT')).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Preservation: passes on both the pre-fix and the fixed code
|
||||||
|
it('should register shutdown handlers for SIGTERM and SIGINT', () => {
|
||||||
|
loadLogger()
|
||||||
|
|
||||||
|
expect(addedListeners('SIGTERM').length).toBeGreaterThanOrEqual(1)
|
||||||
|
expect(addedListeners('SIGINT').length).toBeGreaterThanOrEqual(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should log the shutdown message before ending the logger', () => {
|
||||||
|
const logger = loadLogger()
|
||||||
|
|
||||||
|
addedListeners('SIGTERM')[0]('SIGTERM')
|
||||||
|
|
||||||
|
expect(logger.info).toHaveBeenCalledWith('Initiating graceful shutdown...', { component: 'application' })
|
||||||
|
expect(logger.end).toHaveBeenCalledTimes(1)
|
||||||
|
expect((logger.info as jest.Mock).mock.invocationCallOrder[0])
|
||||||
|
.toBeLessThan((logger.end as jest.Mock).mock.invocationCallOrder[0])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
+17
-2
@@ -155,12 +155,27 @@ export const withTiming = async <T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Graceful shutdown
|
// Graceful shutdown
|
||||||
|
// WHY: `next build` workers (and dev HMR re-evaluations) load this module repeatedly and can
|
||||||
|
// receive both SIGTERM and SIGINT; an unguarded handler logged again after `logger.end()`,
|
||||||
|
// which threw ERR_STREAM_WRITE_AFTER_END.
|
||||||
|
// DECISION: register once per process (flag on `process`, where the listeners live), use
|
||||||
|
// `once` so our listener does not linger for repeated signals, and never write to an ended stream.
|
||||||
|
// The guard is our own flag: winston's Logger is a readable-stream@3 Transform without `writableEnded`.
|
||||||
|
const SHUTDOWN_HANDLERS_KEY = Symbol.for('mozdit.logger.shutdownHandlersRegistered')
|
||||||
|
let hasShutdownStarted = false
|
||||||
|
|
||||||
const gracefulShutdown = () => {
|
const gracefulShutdown = () => {
|
||||||
|
if (hasShutdownStarted) return
|
||||||
|
hasShutdownStarted = true
|
||||||
createComponentLogger('application').info('Initiating graceful shutdown...')
|
createComponentLogger('application').info('Initiating graceful shutdown...')
|
||||||
logger.end()
|
logger.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('SIGTERM', gracefulShutdown)
|
const processState = process as unknown as Record<symbol, boolean | undefined>
|
||||||
process.on('SIGINT', gracefulShutdown)
|
if (!processState[SHUTDOWN_HANDLERS_KEY]) {
|
||||||
|
processState[SHUTDOWN_HANDLERS_KEY] = true
|
||||||
|
process.once('SIGTERM', gracefulShutdown)
|
||||||
|
process.once('SIGINT', gracefulShutdown)
|
||||||
|
}
|
||||||
|
|
||||||
export default logger
|
export default logger
|
||||||
|
|||||||
Reference in New Issue
Block a user