Reference site: Example Studio on ipal-kit (reference/), index for agents, CI job

reference/ is one complete client site on the plugin (made-up company, pl/en,
MongoDB, every library block and template, token standard light/dark, forms,
consent, SEO/GEO, enforced CSP, 2FA, base + demo seeds, Coolify runbook,
smoke tests). It uses the plugin as file:.. (injected) and is not shipped.

- docs/agent/reference-site/INDEX.md (generated by scripts/reference-index.mjs,
  kept current by test/referenceIndex.test.ts)
- AGENT.md section and pointers in ipal-site, ipal-setup, ipal-reference,
  ipal-upgrade, ipal-block; release steps in PROGRAMISTA §8.1b
- CI: reference (fast) on every push, reference-full on main; doctor steps
  wired, commented until ipal-doctor ships

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 15:17:11 +01:00
co-authored by Claude Opus 5.5
parent 8bb5ebd394
commit 8adac41f92
129 changed files with 18440 additions and 1 deletions
+26
View File
@@ -0,0 +1,26 @@
/**
* Creates (or resets) the smoke-test admin with a known TOTP secret, so e2e/smoke.spec.ts signs in through
* the real 2FA screen instead of skipping it. LOCAL / CI database only:
* pnpm payload run e2e/create-test-admin.ts
* Values come from E2E_ADMIN_EMAIL / E2E_ADMIN_PASSWORD / E2E_TOTP_SECRET (.env.example). Not a seed: seeds
* never create users (docs/seeding.md).
*/
import config from '@payload-config'
import { isLocalDatabase } from '@intecion/ipal-kit/seed'
import { getPayload } from 'payload'
const { E2E_ADMIN_EMAIL: email, E2E_ADMIN_PASSWORD: password, E2E_TOTP_SECRET: totpSecret } = process.env
if (!email || !password || !totpSecret) {throw new Error('Set E2E_ADMIN_EMAIL, E2E_ADMIN_PASSWORD and E2E_TOTP_SECRET (.env.example).')}
if (process.env.NODE_ENV === 'production' && !process.env.CI) {throw new Error('Refusing: NODE_ENV=production outside CI.')}
if (!isLocalDatabase(process.env.DATABASE_URI ?? '')) {throw new Error('Refusing: DATABASE_URI is not a local database.')}
const payload = await getPayload({ config })
const data = { email, hasTotp: true, password, roles: ['admin'], totpSecret }
const found = await payload.find({ collection: 'users', limit: 1, overrideAccess: true, where: { email: { equals: email } } })
if (found.docs[0]) {
await payload.update({ id: found.docs[0].id, collection: 'users', data: data as never, overrideAccess: true })
} else {
await payload.create({ collection: 'users', data: data as never, overrideAccess: true })
}
console.log(`[e2e] test admin ready: ${email}`)
process.exit(0)
+140
View File
@@ -0,0 +1,140 @@
import { expect, type Page, test } from '@playwright/test'
import { totp } from './totp'
/**
* Smoke tests of the reference site — every convention a client site must keep working after a plugin release.
* Run against a built, seeded site (playwright.config.ts). Both languages where it applies.
*/
const LOCALES = [
{ blog: '/pl/blog', code: 'pl', contact: '/pl/kontakt', home: '/pl', showcase: '/pl/bloki' },
{ blog: '/en/blog', code: 'en', contact: '/en/contact', home: '/en', showcase: '/en/blocks' },
]
async function rejectCookies(page: Page) {
const reject = page.getByRole('button', { name: /^(Odrzuć|Reject)$/ })
if (await reject.isVisible().catch(() => false)) {await reject.click()}
}
test('/ redirects to the default locale', async ({ request }) => {
const res = await request.get('/', { maxRedirects: 0 })
expect([307, 308]).toContain(res.status())
expect(res.headers().location).toMatch(/\/pl$/)
})
for (const l of LOCALES) {
test(`${l.code}: home renders with one h1, no console errors, both themes`, async ({ page }) => {
const errors: string[] = []
page.on('console', (m) => m.type() === 'error' && errors.push(m.text()))
await page.goto(l.home)
await expect(page.locator('h1')).toHaveCount(1)
await expect(page.locator('[data-ipal-block="hero"]')).toBeVisible()
await rejectCookies(page)
await page.getByRole('switch').first().click()
await expect(page.locator('html')).toHaveAttribute('data-theme', /dark|light/)
expect(errors, errors.join('\n')).toEqual([])
})
test(`${l.code}: the showcase renders every library block, also on the inverse surface`, async ({ page }) => {
await page.goto(l.showcase)
const slugs = await page.locator('[data-ipal-block]').evaluateAll((els) => [...new Set(els.map((e) => (e as HTMLElement).dataset.ipalBlock))])
expect(slugs.length).toBeGreaterThanOrEqual(15)
expect(await page.locator('[data-ipal-block][data-surface="inverse"]').count()).toBeGreaterThanOrEqual(15)
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/)
})
test(`${l.code}: the blog archive lists entries that open`, async ({ page }) => {
await page.goto(l.blog)
const first = page.locator('[data-ipal-block="entryList"] h3 a').first()
await expect(first).toBeVisible()
await first.click()
await expect(page.locator('h1')).toHaveCount(1)
})
test(`${l.code}: the contact form sends`, async ({ page }) => {
await page.goto(l.contact)
await rejectCookies(page)
const form = page.locator('form[data-ipal="form"]').first()
await form.locator('input[name="name"]').fill('Test Smoke')
await form.locator('input[name="email"]').fill('[email protected]')
await form.locator('textarea[name="message"]').fill('Smoke test message.')
await form.locator('input[name="consent"]').check()
// Turnstile (test keys) puts its token in a hidden input once solved — submitting earlier is a turnstile failure
await expect(form.locator('input[name="cf-turnstile-response"]')).not.toHaveValue('', { timeout: 15_000 })
await form.locator('button[type="submit"]').click()
await expect(page.locator('[data-ipal="form-success"]')).toBeVisible({ timeout: 15_000 })
})
}
test('every sitemap URL answers 200 with a title, canonical, hreflang and JSON-LD', async ({ page, request }) => {
const xml = await (await request.get('/sitemap.xml')).text()
// KNOWN plugin gap (reported 2026-10-29): the sitemap lists the page assigned as 404, which answers 404.
// Remove this filter when ipal-kit leaves the notFound page out of the sitemap.
const KNOWN_404 = ['/pl/nie-znaleziono', '/en/page-not-found']
const urls = [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => new URL(m[1]).pathname).filter((p) => !KNOWN_404.includes(p))
expect(urls.length).toBeGreaterThan(20)
for (const path of urls) {
const res = await page.goto(path)
expect(res?.status(), path).toBe(200)
await expect(page, path).toHaveTitle(/\S/)
expect(await page.locator('link[rel="canonical"]').count(), path).toBe(1)
expect(await page.locator('link[hreflang]').count(), path).toBeGreaterThanOrEqual(2)
expect(await page.locator('script[type="application/ld+json"]').count(), path).toBeGreaterThan(0)
}
})
test('SEO and GEO routes respond', async ({ request }) => {
const robots = await (await request.get('/robots.txt')).text()
expect(robots).toContain('Sitemap:')
expect(robots).toMatch(/Disallow: \/admin/)
expect(await (await request.get('/llms.txt')).text()).toContain('Example Studio')
expect((await request.get('/llms-full.txt')).status()).toBe(200)
expect(await (await request.get('/md/pl')).text()).toMatch(/^#|\n#/)
expect((await request.get('/api/health')).status()).toBe(200)
const mcp = await request.post('/api/mcp', { data: { id: 1, jsonrpc: '2.0', method: 'tools/list' } })
expect(await mcp.text()).toContain('get_page')
})
test('security headers: CSP enforced, no X-Powered-By', async ({ request }) => {
const headers = (await request.get('/pl')).headers()
expect(headers['content-security-policy']).toBeTruthy()
expect(headers['x-frame-options']).toBe('DENY')
expect(headers['x-powered-by']).toBeUndefined()
})
test('a missing page is a 404 with the panel 404 content', async ({ page }) => {
const res = await page.goto('/pl/nie-ma-takiej-strony')
expect(res?.status()).toBe(404)
await expect(page.getByRole('heading', { level: 1 })).toBeVisible()
})
test('consent: reject sets no analytics, the choice is logged', async ({ page }) => {
const logged = page.waitForResponse((r) => r.url().endsWith('/api/ipal/consent') && r.request().method() === 'POST')
await page.goto('/pl')
await page.getByRole('button', { name: 'Odrzuć' }).click()
expect((await logged).status()).toBe(201)
const cookies = await page.context().cookies()
expect(cookies.some((c) => /^_ga/.test(c.name))).toBe(false)
expect(cookies.some((c) => c.name === 'cookie-consent')).toBe(true)
})
test('admin: sign in through 2FA, agency credit, panel link preview', async ({ page, request }) => {
const head = await (await request.get('/admin/login')).text()
expect(head).toMatch(/noindex/)
expect(head).toMatch(/og:site_name/)
const { E2E_ADMIN_EMAIL: email, E2E_ADMIN_PASSWORD: password, E2E_TOTP_SECRET: secret } = process.env
test.skip(!email || !password || !secret, 'E2E_* test admin not configured')
await page.goto('/admin/login')
await page.fill('#field-email', email!)
await page.fill('#field-password', password!)
await page.click('.form-submit button')
await page.waitForURL(/verify-totp|\/admin(\?|$)/, { waitUntil: 'commit' })
if (page.url().includes('verify-totp')) {
// six one-digit inputs: type the code into the first, focus moves on by itself
const firstDigit = page.getByRole('textbox').first()
await firstDigit.click()
await page.keyboard.type(totp(secret!))
}
await expect(page).toHaveTitle(/Dashboard|Pulpit/, { timeout: 20_000 })
await expect(page.getByText(/Intecion/).first()).toBeVisible()
})
+15
View File
@@ -0,0 +1,15 @@
import { createHmac } from 'node:crypto'
/** RFC 6238 TOTP (SHA-1, 6 digits, 30 s) — the code an authenticator app shows for `secret` (base32). */
export function totp(secret: string, now = Date.now()): string {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
let bits = ''
for (const ch of secret.replace(/=+$/, '').toUpperCase()) {bits += alphabet.indexOf(ch).toString(2).padStart(5, '0')}
const key = Buffer.from((bits.match(/.{8}/g) ?? []).map((b) => parseInt(b, 2)))
const counter = Buffer.alloc(8)
counter.writeBigUInt64BE(BigInt(Math.floor(now / 1000 / 30)))
const hmac = createHmac('sha1', key).update(counter).digest()
const offset = hmac[hmac.length - 1] & 0xf
const code = (hmac.readUInt32BE(offset) & 0x7fffffff) % 1_000_000
return code.toString().padStart(6, '0')
}