Merge commit '977872b' into claude/ipal-doctor-build

# Conflicts:
#	src/modules/seo/buildSitemapEntries.ts
This commit is contained in:
Radosław Smoliński
2026-10-29 16:08:40 +01:00
37 changed files with 518 additions and 47 deletions
+16
View File
@@ -4,6 +4,7 @@ import { afterEach, describe, expect, test, vi } from 'vitest'
import type { I18nConfig } from '../src/modules/i18n/types.js'
import { createSearchRoute } from '../src/modules/content/createSearchRoute.js'
import { createMcpRoute } from '../src/modules/mcp/createMcpRoute.js'
const config: I18nConfig = {
@@ -86,6 +87,21 @@ describe('createMcpRoute', () => {
expect((await call('search_content', { query: 'nas' })).content[0].text).toContain('O nas')
})
test('search_content and the search route leave out the page assigned as the 404 page', async () => {
const withNotFound = [...pages, { id: 5, slug: 'nie-znaleziono', _status: 'published', title: 'Nie znaleziono nas' }]
;(payload.find as ReturnType<typeof vi.fn>).mockResolvedValue({ docs: withNotFound })
;(payload.findGlobal as ReturnType<typeof vi.fn>).mockResolvedValue({ homepage: 4, notFound: 5, siteName: 'Acme' })
const text = (await call('search_content', { query: 'nas' })).content[0].text
expect(text).toContain('O nas')
expect(text).not.toContain('nie-znaleziono')
// The site search route uses the same searchContent.
const search = createSearchRoute({ config, getCachedPayload: async () => payload, rateLimit: false })
const body = (await (await search(new Request('https://acme.pl/api/search?q=nas'))).json()) as { results: { slug: string }[] }
// (the fake find ignores the query, so every published page comes back — except the 404 page)
expect(body.results.map((r) => r.slug)).toEqual(['o-nas', 'strona-glowna'])
;(payload.find as ReturnType<typeof vi.fn>).mockResolvedValue({ docs: pages })
})
test('tool errors stay generic (no internals leak)', async () => {
vi.spyOn(console, 'warn').mockImplementation(() => {})
;(payload.find as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error('ECONNREFUSED db:5432'))
+8
View File
@@ -79,6 +79,14 @@ describe('buildImagesConfig', () => {
expect(config.dangerouslyAllowLocalIP).toBe(true)
expect(buildImagesConfig({ production: false, serverUrl: 'https://staging.acme.pl' }).dangerouslyAllowLocalIP).toBeUndefined()
})
test('production without R2 (the documented default): the site\'s own media are allowed', () => {
const config = buildImagesConfig({ production: true, publicUrl: '', serverUrl: 'https://acme.pl' })
expect(config.remotePatterns).toEqual([{ hostname: 'acme.pl', pathname: '/api/media/file/**', protocol: 'https' }])
expect(config.dangerouslyAllowLocalIP).toBeUndefined()
// A local production build (CI, `next start` on localhost) still never opens private IPs.
expect(buildImagesConfig({ production: true, serverUrl: 'http://localhost:3000' }).dangerouslyAllowLocalIP).toBeUndefined()
})
})
describe('buildMediaPlaceholderHook', () => {
+21
View File
@@ -108,6 +108,14 @@ describe('createSeeder', () => {
db: sqliteAdapter({ client: { url: 'file::memory:' }, push: true }),
editor: lexicalEditor(),
globals: [
{
slug: 'look',
fields: [
{ name: 'mode', type: 'select', defaultValue: 'light', options: ['light', 'dark', 'system'] },
{ name: 'toggle', type: 'checkbox', defaultValue: true },
{ name: 'greeting', type: 'text', defaultValue: 'Hello' },
],
},
{
slug: 'header',
fields: [
@@ -241,6 +249,19 @@ describe('createSeeder', () => {
expect((await seeder().fillGlobal('header', { tagline: { pl: 'Inne' } })).status).toBe('skip (exists)')
})
test('fillGlobal: a choice still at its default counts as unset; text is never overwritten', async () => {
await payload.updateGlobal({ slug: 'look' as never, data: {} as never }) // first save stores the defaults
const first = await seeder().fillGlobal('look', { greeting: 'Hi', mode: 'system', toggle: false })
expect(first).toMatchObject({ status: 'create' })
expect(first.note).toBe('empty fields filled: mode, toggle')
const look = (await payload.findGlobal({ slug: 'look' as never })) as { greeting: string; mode: string; toggle: boolean }
expect(look).toMatchObject({ greeting: 'Hello', mode: 'system', toggle: false })
// An editor's choice that differs from the default stays.
await payload.updateGlobal({ slug: 'look' as never, data: { mode: 'dark' } as never })
await seeder().fillGlobal('look', { mode: 'system' })
expect(((await payload.findGlobal({ slug: 'look' as never })) as { mode: string }).mode).toBe('dark')
})
test('production guard: update refused on production or a non-local database unless IPAL_SEED_ALLOW_PROD_UPDATE=1', () => {
vi.stubEnv('NODE_ENV', 'production')
const only = ['pages:kontakt']
+27
View File
@@ -259,6 +259,33 @@ describe('sitemap route: split, cache, errors', () => {
})
})
describe('system pages without a URL of their own', () => {
const settings = { homepage: { id: 1, slug: { en: 'home', pl: 'start' } }, notFound: { id: 2, slug: { en: 'not-found-page', pl: 'nie-znaleziono' } } }
const pages = [
{ id: 1, slug: { en: 'home', pl: 'start' }, _status: 'published', title: 'Home' },
{ id: 2, slug: { en: 'not-found-page', pl: 'nie-znaleziono' }, _status: 'published', title: 'Not found' },
{ id: 3, slug: { en: 'contact', pl: 'kontakt' }, _status: 'published', title: 'Contact' },
]
test('the assigned 404 page is left out of the sitemap, the site index and llms.txt', async () => {
const payload = fakePayload({ pages })
payload.findGlobal.mockResolvedValue(settings)
const sitemap = await buildSitemapEntries({ baseUrl: 'https://acme.pl', config, payload: payload as never })
expect(sitemap.map((e) => e.url)).toEqual(['https://acme.pl/pl', 'https://acme.pl/en', 'https://acme.pl/pl/kontakt', 'https://acme.pl/en/contact'])
const flat = fakePayload({ pages: pages.map((p) => ({ ...p, slug: p.slug.pl })) })
flat.findGlobal.mockResolvedValue(settings)
expect((await collectSiteIndex({ config: single, payload: flat as never })).map((e) => e.path)).toEqual(['/', '/kontakt'])
expect(await buildLlmsTxt({ baseUrl: 'https://acme.pl', config: single, payload: flat as never })).not.toContain('nie-znaleziono')
})
test('a 404 page that is also the homepage stays listed', async () => {
const payload = fakePayload({ pages: pages.slice(0, 1) })
payload.findGlobal.mockResolvedValue({ homepage: { id: 1 }, notFound: 1 })
expect(await buildSitemapEntries({ baseUrl: 'https://acme.pl', config, payload: payload as never })).toHaveLength(2)
})
})
describe('collectSiteIndex and llms.txt', () => {
const pages = Array.from({ length: 1205 }, (_, i) => ({ id: i, slug: `p${i}`, title: `Page ${i}` }))
+80
View File
@@ -0,0 +1,80 @@
import type { Config } from 'payload'
import { describe, expect, test } from 'vitest'
import { bottomOverlap } from '../src/modules/consent/CookieButton.js'
import { TOTP_TEXTS } from '../src/modules/security/totp/totpTexts.js'
import { ipalKit } from '../src/plugin.js'
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }, { code: 'en', label: 'English' }] }
/** Stand-in for @clocklimited/payload-2fa: its own texts and the two views, as the package adds them. */
const fakeTotp = () => (config: Config) => ({
...config,
admin: {
...config.admin,
components: {
...config.admin?.components,
views: {
...config.admin?.components?.views,
SetupTOTP: { Component: { path: 'pkg#TOTPSetup' }, path: 'setup-totp' },
VerifyTOTP: { Component: { path: 'pkg#TOTPVerify' }, path: 'verify-totp' },
},
},
},
i18n: {
...config.i18n,
translations: {
...config.i18n?.translations,
en: { ...config.i18n?.translations?.en, totpPlugin: { verify: { title: 'Verification' } } },
pl: { ...config.i18n?.translations?.pl, totpPlugin: { verify: { title: 'Weryfikacja' } } },
},
},
})
const base = (translations?: Record<string, unknown>): Config =>
({ collections: [{ slug: 'users', auth: true, fields: [] }], i18n: translations ? { translations } : undefined, secret: 'test' }) as unknown as Config
type Translations = Record<string, { totpPlugin: { setup: Record<string, string>; verify: { title: string } } }>
describe('2FA texts', () => {
test('ipal-kit texts go over the package, the project over both; screens get a tab title', async () => {
const config = await ipalKit({ i18n, twoFactor: { issuer: 'Acme', plugin: fakeTotp } } as never)(
base({ en: { totpPlugin: { verify: { title: 'Project check' } } } }),
)
const t = config.i18n!.translations as Translations
expect(t.pl.totpPlugin.verify.title).toBe('Weryfikacja dwuetapowa')
expect(t.pl.totpPlugin.setup.enterCode).toBe('Wpisz {digits}-cyfrowy kod z aplikacji:')
expect(t.en.totpPlugin.verify.title).toBe('Project check')
const views = config.admin!.components!.views as Record<string, { meta?: { title?: string } }>
expect(views.VerifyTOTP.meta?.title).toBe('Weryfikacja dwuetapowa')
expect(views.SetupTOTP.meta?.title).toBe('Weryfikacja dwuetapowa')
})
test("texts: false keeps the package's", async () => {
const config = await ipalKit({ i18n, twoFactor: { issuer: 'Acme', plugin: fakeTotp, texts: false } } as never)(base())
expect((config.i18n!.translations as Translations).pl.totpPlugin.verify.title).toBe('Weryfikacja')
})
test('same keys in English and Polish, short and formal', () => {
const keys = (o: object, p = ''): string[] =>
Object.entries(o).flatMap(([k, v]) => (typeof v === 'object' ? keys(v as object, `${p}${k}.`) : [`${p}${k}`]))
expect(keys(TOTP_TEXTS.pl)).toEqual(keys(TOTP_TEXTS.en))
const all = [...Object.values(TOTP_TEXTS.pl.totpPlugin.setup), TOTP_TEXTS.pl.totpPlugin.fieldDescription]
expect(all.some((s) => /\b(?:Tw[oó]j|Będziesz|Masz)\b/.test(s))).toBe(false)
expect(TOTP_TEXTS.en.totpPlugin.forceTotp.label.split(' ').length).toBeLessThanOrEqual(3)
})
})
describe('CookieButton lift above the footer', () => {
test('moves up by the visible part of the footer', () => {
expect(bottomOverlap([], 800)).toBe(0)
expect(bottomOverlap([1200], 800)).toBe(0) // footer below the fold
expect(bottomOverlap([650], 800)).toBe(150)
expect(bottomOverlap([700, 650], 800)).toBe(150) // the highest one counts
})
test('never pushes the button off the screen', () => {
expect(bottomOverlap([-500], 800)).toBe(704)
})
})