noindex tooling, content/noindex/component/testing guidelines for agents

- IPAL_NOINDEX=1: whole-site noindex for staging (robots Disallow /, robots
  meta noindex,nofollow, X-Robots-Tag via buildSecurityHeaders).
- Markdown mirrors and llms files: X-Robots-Tag noindex; Markdown adds a
  Link rel=canonical to the HTML page.
- buildNoindexField refuses noindex on the homepage and archive pages.
- AGENT.md §0c: writing pages for Google and AI (structure, answer-first,
  facts, E-E-A-T, entity consistency, sameAs, aiSummary, meta) and a
  when-to-noindex table (legal pages stay indexed by default; drafts instead
  of noindexed pages; staging via env).
- AGENT.md §6.0: ten component rules (small, Button styled once, buttons as
  '+ Add Button' array, variants, panel clarity); audit warns on buttons
  styled inside sections.
- AGENT.md §8a + smoke.spec.template.ts: what to test in a client project;
  PROGRAMISTA §8.1a: how the plugin itself is tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-16 03:13:44 +02:00
co-authored by Claude Opus 5.5
parent 8e2dd28b83
commit f7466cf77f
13 changed files with 314 additions and 10 deletions
+13
View File
@@ -9,6 +9,7 @@ import { buildConfig, getPayload } from 'payload'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { resolveRoute } from '../src/modules/content/resolveRoute.js'
import { buildNoindexField } from '../src/modules/seo/buildNoindexField.js'
import { ipalKit } from '../src/plugin.js'
let payload: Payload
@@ -21,6 +22,7 @@ beforeAll(async () => {
fields: [
{ name: 'title', type: 'text' },
{ name: 'slug', type: 'text', localized: true },
buildNoindexField(),
],
versions: { drafts: true },
},
@@ -74,3 +76,14 @@ describe('archive listing', () => {
expect(preview.totalDocs).toBe(2)
})
})
describe('noindex protection', () => {
test('the homepage cannot be set to noindex; an ordinary page can', async () => {
const home = await payload.create({ collection: 'pages' as never, data: { _status: 'published', slug: 'start', title: 'Start' } as never })
const other = await payload.create({ collection: 'pages' as never, data: { _status: 'published', slug: 'dziekujemy', title: 'Dziękujemy' } as never })
await payload.updateGlobal({ slug: 'site-settings' as never, data: { homepage: home.id, siteName: 'Acme' } as never })
await expect(payload.update({ collection: 'pages' as never, data: { noindex: true } as never, id: home.id })).rejects.toThrow(/Exclude from indexing/)
const updated = (await payload.update({ collection: 'pages' as never, data: { noindex: true } as never, id: other.id })) as { noindex?: boolean }
expect(updated.noindex).toBe(true)
})
})
+23
View File
@@ -236,3 +236,26 @@ describe('buildUploadSecurityHeaders', () => {
expect(csp).not.toContain('script-src')
})
})
describe('site-wide noindex (IPAL_NOINDEX) and Markdown headers', () => {
test('staging blocks crawling everywhere', async () => {
const { vi } = await import('vitest')
vi.stubEnv('IPAL_NOINDEX', '1')
try {
expect(buildRobots({ baseUrl: 'https://staging.acme.pl' })).toEqual({ rules: { disallow: ['/'], userAgent: '*' } })
expect(buildSecurityHeaders().find((h) => h.key === 'X-Robots-Tag')?.value).toBe('noindex, nofollow')
const { buildMetadata } = await import('../src/modules/seo/buildMetadata.js')
expect(buildMetadata({ config, locale: 'pl', slugs: { pl: 'x' } }).robots).toEqual({ follow: false, index: false })
} finally {
vi.unstubAllEnvs()
}
expect(buildSecurityHeaders().some((h) => h.key === 'X-Robots-Tag')).toBe(false)
})
test('Markdown mirrors are noindex with a canonical link to the HTML page', async () => {
const { markdownResponse } = await import('../src/modules/content/createMarkdownRenderer.js')
const res = markdownResponse('# x', { canonical: 'https://acme.pl/pl/o-nas' })
expect(res.headers.get('x-robots-tag')).toBe('noindex')
expect(res.headers.get('link')).toBe('<https://acme.pl/pl/o-nas>; rel="canonical"')
})
})