Search leaves out the 404 page: searchContent, the search route, MCP search_content
searchContent / listContent read Site settings once (depth 0, homepage + notFound) and skip unlistedPageIds; createSearchRoute and the MCP route pass settingsSlug. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3645e61f7d
commit
6b2c9b3cc6
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user