feat(deploy): indexability guard and production SEO launch suite (MITHOME-127)

The staging noindex (MITHOME-116) hinges on a build variable; leaking it
into production would silently drop the site from Google. deploy.sh now
refuses to build production when NEXT_PUBLIC_DEPLOY_ENV=staging is set,
and after every deploy runs scripts/check-indexability.sh, expecting an
indexable production and a blocked staging (node tests cover both ways,
stray noindex and unreachable endpoints; added to pre-deploy tests).

A separate Playwright project, production-seo (npm run
test:seo:production), checks robots.txt, that all 12 sitemap URLs are
final/indexable with self canonicals and sitemap hreflangs, SSR content
and links, the / -> /hu redirect and real 404s; host redirects are gated
until the production domain is live. Verified on a production-mode build
of a staging DB copy (5 passed) and failing as expected against staging.

eslint now ignores generated test output (playwright-report, test-results,
coverage), which broke the pre-deploy lint after local e2e runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 13:23:23 +02:00
co-authored by Claude Opus 5.5
parent 104756db7f
commit dc7a777d9f
9 changed files with 286 additions and 10 deletions
+73
View File
@@ -0,0 +1,73 @@
import { expect, test, type APIRequestContext } from '@playwright/test'
/**
* MITHOME-127 — production launch SEO checks (run at go-live and after every
* production release): `BASE_URL=https://mozdit.hu npm run test:seo:production`.
*
* The site must be indexable, every sitemap URL must be final (200, no
* redirect), canonical/hreflang must point at those final URLs, and content +
* internal links must be in the server-rendered HTML (no JS needed).
* Host-level redirects (http→https, www→apex) are nginx's job (MITHOME-15):
* set SEO_CHECK_HOST_REDIRECTS=1 once the production domain is live.
*/
const text = async (request: APIRequestContext, path: string) => {
const response = await request.get(path, { maxRedirects: 0 })
expect(response.status(), `${path} status`).toBe(200)
return response.text()
}
const locs = (xml: string) => [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1])
const attr = (html: string, pattern: RegExp) => html.match(pattern)?.[1]
test('robots.txt allows crawling and points to the sitemap', async ({ request, baseURL }) => {
const robots = await text(request, '/robots.txt')
expect(robots).not.toMatch(/^Disallow:\s*\/\s*$/im)
expect(robots).toContain(`Sitemap: ${baseURL}/sitemap.xml`)
})
test('every sitemap URL is final, indexable and correctly annotated', async ({ request, baseURL }) => {
const urls = locs(await text(request, '/sitemap.xml'))
expect(urls).toHaveLength(12)
for (const url of urls) {
expect(url.startsWith(`${baseURL}/`), `${url} is on ${baseURL}`).toBe(true)
const html = await text(request, url)
expect(html, `${url} has no noindex`).not.toMatch(/<meta[^>]*name="robots"[^>]*noindex/i)
expect(attr(html, /<link rel="canonical" href="([^"]+)"/), `${url} canonical`).toBe(url)
for (const lang of ['hu', 'en', 'x-default']) {
const alternate = attr(html, new RegExp(`<link rel="alternate" hrefLang="${lang}" href="([^"]+)"`))
expect(urls, `${url} hreflang ${lang} → ${alternate}`).toContain(alternate)
}
}
})
test('content and internal links are in the server-rendered HTML', async ({ request }) => {
const html = await text(request, '/hu')
expect(html).toMatch(/<h1[^>]*>[^<]+/)
for (const path of ['/hu/rolunk', '/hu/szolgaltatasok', '/hu/kapcsolat', '/en']) {
expect(html, `link to ${path}`).toContain(`href="${path}"`)
}
})
test('the site root redirects to /hu in one step', async ({ request }) => {
const response = await request.get('/', { maxRedirects: 0 })
expect([301, 302, 307, 308]).toContain(response.status())
expect(new URL(response.headers()['location'], 'http://x').pathname).toBe('/hu')
})
test('unknown pages return a real 404', async ({ request }) => {
const response = await request.get('/hu/nincs-ilyen-oldal', { maxRedirects: 0 })
expect(response.status()).toBe(404)
})
test('host variants redirect to the canonical origin in one step', async ({ request, baseURL }) => {
test.skip(!process.env.SEO_CHECK_HOST_REDIRECTS, 'nginx host redirects are checked once the production domain is live (MITHOME-15)')
const canonical = new URL(baseURL!)
const variants = [`http://${canonical.host}/hu`, `https://www.${canonical.host}/hu`]
for (const variant of variants) {
const response = await request.get(variant, { maxRedirects: 0 })
expect([301, 308], `${variant} status`).toContain(response.status())
expect(response.headers()['location'], `${variant} target`).toBe(`${canonical.origin}/hu`)
}
})
+4
View File
@@ -16,6 +16,10 @@ const eslintConfig = [
"out/**",
"build/**",
"next-env.d.ts",
// Generated test output (Playwright report/traces, Jest coverage) — not source.
"playwright-report/**",
"test-results/**",
"coverage/**",
],
},
{
+2 -1
View File
@@ -14,7 +14,8 @@
"test:browser": "jest --config jest.config.js src/__tests__/browser-integration.test.ts",
"test:integration": "INTEGRATION_TESTS=1 jest --config jest.config.integration.js src/__tests__/integration.test.ts",
"test:e2e": "E2E_TESTS=1 jest --config jest.config.integration.js src/__tests__/e2e-docker.test.ts",
"test:smoke:staging": "playwright test --config=playwright.config.ts",
"test:smoke:staging": "playwright test --config=playwright.config.ts --project=staging",
"test:seo:production": "playwright test --config=playwright.config.ts --project=production-seo",
"test:docker": "npm run test:integration && npm run test:e2e",
"test:all": "npm run test:unit && npm run test:browser && npm run test:docker",
"test:report": "npm test -- --json --outputFile=test-results.json --silent && node ../scripts/sync-test-management.js",
+15 -2
View File
@@ -1,15 +1,28 @@
import { defineConfig, devices } from '@playwright/test'
// MITHOME-127: two projects with opposite indexing expectations —
// `staging` (smoke, expects noindex) and `production-seo` (expects an
// indexable site). BASE_URL overrides the target of either.
export default defineConfig({
testDir: './e2e',
timeout: 30_000,
retries: process.env.CI ? 1 : 0,
reporter: [['list'], ['html', { open: 'never' }]],
use: {
baseURL: process.env.BASE_URL || 'https://stage.mozdit.hu',
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
projects: [
{
name: 'staging',
testMatch: 'staging-smoke.spec.ts',
use: { ...devices['Desktop Chrome'], baseURL: process.env.BASE_URL || 'https://stage.mozdit.hu' },
},
{
name: 'production-seo',
testMatch: 'production-seo.spec.ts',
use: { ...devices['Desktop Chrome'], baseURL: process.env.BASE_URL || 'https://mozdit.hu' },
},
],
})