Merge claude/reference-site-plugin-fixes: 404 page unlisted, own-origin media, fillGlobal defaults

The page assigned as the 404 page is left out of the sitemap, llms.txt, the site
index, search, the search route and MCP search_content (unlistedPageIds;
createSearchRoute settingsSlug). buildImagesConfig allows the site's own
/api/media/file/** when R2_PUBLIC_URL is empty. fillGlobal treats a choice field
still at its default as empty. i18n.md: renderLabel client wrapper. No conflicts;
one Unreleased CHANGELOG section.
This commit is contained in:
Radosław Smoliński
2026-10-29 15:45:49 +01:00
24 changed files with 226 additions and 24 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
@@ -251,6 +251,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}` }))