cookieScanner.crawl (opt-in) adds "Crawl site" to the Cookie review box. The
site asks the shared scanner service (services/cookie-crawler: Node +
Playwright, Dockerfile, deployed once on Coolify) to crawl its sitemap pages
twice, with no consent and after "Accept all". The service posts cookies,
storage keys and third-party hosts back to POST /api/ipal/cookie-crawl/results
(bearer token, running job only). No browser in the site.
Findings land as drafts through the same merge rules. Anything stored before
consent that is not necessary, and tracker requests before consent, are
violations, flagged on the review entries from the latest crawl only. The
cookie-crawl global keeps the latest result (no history). A dashboard warning
(CookieCrawlAlert) and an opt-in e-mail through the project's mail adapter
follow a crawl with violations or new unknown cookies. Scheduled crawls: a
Coolify scheduled task with the token. ipalEnvRules({ cookieCrawl: true }).
Also: the six older real-Payload tests no longer leave an orphaned
payload generate:types process (typescript.autoGenerate: false).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
120 lines
5.7 KiB
TypeScript
120 lines
5.7 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
|
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import { buildConfig, getPayload } from 'payload'
|
|
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { createContentHelpers } from '../src/modules/frontend/createContentHelpers.js'
|
|
import { ipalKit } from '../src/plugin.js'
|
|
|
|
vi.mock('server-only', () => ({}))
|
|
|
|
/**
|
|
* Sitemap, llms.txt and robots against a real (SQLite) Payload: the batched,
|
|
* `select`-ed, published-only reads must work with the database adapter, and
|
|
* Site Settings → Search & AI / Under construction must reach the output.
|
|
*/
|
|
describe('SEO outputs against a real database', () => {
|
|
let payload: Payload
|
|
let configPromise: Parameters<typeof getPayload>[0]['config']
|
|
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }, { code: 'en', label: 'English' }] } as const
|
|
const helpers = () => createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n })
|
|
const urls = async () => (await helpers().sitemap()).map((e) => e.url).sort()
|
|
|
|
beforeAll(async () => {
|
|
configPromise = buildConfig({
|
|
collections: [
|
|
{ slug: 'users', auth: true, fields: [] },
|
|
{
|
|
slug: 'pages',
|
|
fields: [
|
|
{ name: 'title', type: 'text' },
|
|
{ name: 'slug', type: 'text', index: true, localized: true },
|
|
{ name: 'noindex', type: 'checkbox' },
|
|
],
|
|
versions: { drafts: true },
|
|
},
|
|
{ slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media-seo') } },
|
|
],
|
|
db: sqliteAdapter({ client: { url: 'file::memory:' }, push: true }),
|
|
editor: lexicalEditor(),
|
|
plugins: [ipalKit({ access: { authCollection: 'users' }, i18n, pages: { slug: 'pages' }, twoFactor: false })],
|
|
secret: 'seo-integration-test-secret',
|
|
telemetry: false,
|
|
typescript: { autoGenerate: false }, // no orphaned `payload generate:types` child
|
|
})
|
|
payload = await getPayload({ config: configPromise })
|
|
|
|
const create = async (slug: Record<string, string>, extra: Record<string, unknown> = {}) => {
|
|
const doc = await payload.create({
|
|
collection: 'pages' as never,
|
|
data: { slug: slug.pl, _status: 'published', title: slug.pl, ...extra } as never,
|
|
locale: 'pl' as never,
|
|
})
|
|
await payload.update({ id: doc.id, collection: 'pages' as never, data: { slug: slug.en } as never, locale: 'en' as never })
|
|
return doc
|
|
}
|
|
const home = await create({ en: 'home', pl: 'start' })
|
|
await create({ en: 'about', pl: 'o-nas' })
|
|
await create({ en: 'hidden', pl: 'ukryta' }, { noindex: true })
|
|
await create({ en: 'draft', pl: 'szkic' }, { _status: 'draft' })
|
|
await payload.updateGlobal({ slug: 'site-settings' as never, data: { homepage: home.id, siteName: 'Acme' } as never })
|
|
}, 60_000)
|
|
|
|
afterAll(async () => {
|
|
await payload?.destroy()
|
|
})
|
|
|
|
test('sitemap: published and indexable pages in every language', async () => {
|
|
expect(await urls()).toEqual(['https://acme.pl/en', 'https://acme.pl/en/about', 'https://acme.pl/pl', 'https://acme.pl/pl/o-nas'])
|
|
})
|
|
|
|
test('project overrides: sitemapEntries has the last word', async () => {
|
|
const h = createContentHelpers({
|
|
baseUrl: 'https://acme.pl',
|
|
config: configPromise,
|
|
i18n,
|
|
sitemapEntries: (entries) => [...entries.filter((e) => !e.url.endsWith('/en')), { url: 'https://acme.pl/custom' }],
|
|
})
|
|
const list = (await h.sitemap()).map((e) => e.url)
|
|
expect(list).toContain('https://acme.pl/custom')
|
|
expect(list).not.toContain('https://acme.pl/en')
|
|
})
|
|
|
|
test('verification codes and AI crawler rules from Site Settings → Search & AI', async () => {
|
|
await payload.updateGlobal({
|
|
slug: 'site-settings' as never,
|
|
data: {
|
|
aiCrawlers: { policy: 'block-training', rules: [{ access: 'disallow', userAgent: 'PerplexityBot' }] },
|
|
searchVerification: { google: '<meta name="google-site-verification" content="G-tok_1" />' },
|
|
} as never,
|
|
})
|
|
const stored = (await payload.findGlobal({ slug: 'site-settings' as never })) as { searchVerification?: { google?: string } }
|
|
expect(stored.searchVerification?.google).toBe('G-tok_1')
|
|
|
|
const meta = await helpers().generatePageMetadata('pl', ['o-nas'])
|
|
expect(meta.verification).toEqual({ google: 'G-tok_1' })
|
|
|
|
const rules = (await helpers().getRobots()).rules as { disallow?: string[]; userAgent: string | string[] }[]
|
|
expect(rules).toContainEqual({ disallow: ['/'], userAgent: ['PerplexityBot'] })
|
|
const assistants = rules.find((r) => Array.isArray(r.userAgent) && r.userAgent.includes('ClaudeBot'))
|
|
expect(assistants?.userAgent).not.toContain('PerplexityBot')
|
|
// the code-only handler ignores the panel
|
|
expect(helpers().robots().rules).not.toContainEqual({ disallow: ['/'], userAgent: ['PerplexityBot'] })
|
|
})
|
|
|
|
test('under construction: sitemap and llms.txt list only the open pages', async () => {
|
|
await payload.updateGlobal({ slug: 'site-settings' as never, data: { construction: { enabled: true } } as never, locale: 'pl' as never })
|
|
expect(await urls()).toEqual(['https://acme.pl/en', 'https://acme.pl/pl'])
|
|
const llms = await (await helpers().llmsRoute()).text()
|
|
expect(llms).not.toContain('o-nas')
|
|
const unfiltered = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n, underConstructionSeo: false })
|
|
expect(await unfiltered.sitemap()).toHaveLength(4)
|
|
await payload.updateGlobal({ slug: 'site-settings' as never, data: { construction: { enabled: false } } as never, locale: 'pl' as never })
|
|
expect(await urls()).toHaveLength(4)
|
|
})
|
|
})
|