teqo-backup/tests/unit/importMapS3UploadHandler.unit.spec.ts
Francisco Solla fea6c64514 fix(admin): restaura S3ClientUploadHandler no importMap — admin em branco em prod (4ª recorrência da classe OPS69)
O importMap commitado perdeu a entrada do handler S3 no 1c865bd8
(regenerado sem as envs S3_*): com S3_* em prod, getFromImportMap
retorna undefined e a raiz do Payload não monta — tela branca, zero
erros de console, invisível no loop local (storage local em dev/test).

Fix da causa: regeneração com S3_* dummy (+2 linhas). Prevenção no
mesmo PR — o guard planejado no OPS69 (depends #77/#87) que nunca
existiu: pin unit, guard CI+deploy que regenera com envs dummy e falha
em divergência, wrapper do generate:importmap que injeta as envs, e
contrato compartilhado da chave. Post-mortem + changelog incluídos.
2026-08-26 20:27:22 -03:00

29 lines
1.2 KiB
TypeScript

import { readFileSync } from 'node:fs'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import {
S3_UPLOAD_HANDLER_IMPORT_PREFIX,
S3_UPLOAD_HANDLER_KEY,
} from '../../scripts/lib/importMapContract.mjs'
// The admin goes blank in production when this entry is missing: with the
// S3_* envs set, the media collection uses the s3Storage plugin and the admin
// config references this handler — getFromImportMap returns undefined, the
// Payload root never mounts, and the admin renders an empty page with zero
// console errors (class OPS69/OPS72/OPS73; orphaned again by 1c865bd8,
// 2026-08-23). Regenerating the importMap without the S3_* envs silently
// removes the entry — this pin fails the exact drift.
const importMapPath = path.resolve(__dirname, '../../src/app/(payload)/admin/importMap.js')
describe('importMap (admin)', () => {
it('keeps the S3ClientUploadHandler entry required by the prod S3 storage', () => {
const source = readFileSync(importMapPath, 'utf8')
// Import + map entry, like the generator emits (+2 lines in the file).
expect(source).toContain(S3_UPLOAD_HANDLER_IMPORT_PREFIX)
expect(source).toContain(`${S3_UPLOAD_HANDLER_KEY}": S3ClientUploadHandler_`)
})
})