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:
co-authored by
Claude Opus 5.5
parent
104756db7f
commit
dc7a777d9f
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
# MITHOME-127: indexelhetőségi őr — a telepített oldal robots.txt-je,
|
||||
# sitemapje és noindex-jelölése egyezik-e a környezet elvárásával.
|
||||
#
|
||||
# Használat: scripts/check-indexability.sh <base-url> <indexable|blocked>
|
||||
# indexable — production: nincs noindex, a robots.txt enged és a sitemapre
|
||||
# mutat, a sitemap nem üres
|
||||
# blocked — staging: noindex, mindent tiltó robots.txt, üres sitemap
|
||||
#
|
||||
# WHY: a staging tiltása a NEXT_PUBLIC_DEPLOY_ENV build-változón múlik
|
||||
# (MITHOME-116). Ha az éles build hibásan kapja meg, a Google csendben
|
||||
# kiveszi az oldalt a találatok közül — ezt a deploy azonnal jelezze.
|
||||
# Kilépési kód: 0 = egyezik, 1 = eltérés, 2 = hibás használat / elérhetetlen.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
BASE_URL="${1:-}"
|
||||
EXPECT="${2:-}"
|
||||
if [ -z "$BASE_URL" ] || { [ "$EXPECT" != "indexable" ] && [ "$EXPECT" != "blocked" ]; }; then
|
||||
echo "Használat: $0 <base-url> <indexable|blocked>" >&2
|
||||
exit 2
|
||||
fi
|
||||
BASE_URL="${BASE_URL%/}"
|
||||
|
||||
fetch() {
|
||||
# -f: a 4xx/5xx válasz (pl. hiányzó robots.txt) is hiba, nem üres tartalom.
|
||||
curl -fsS --max-time 20 "$BASE_URL$1"
|
||||
}
|
||||
|
||||
ROBOTS="$(fetch /robots.txt)" || { echo "❌ robots.txt nem érhető el: $BASE_URL/robots.txt" >&2; exit 2; }
|
||||
SITEMAP="$(fetch /sitemap.xml)" || { echo "❌ sitemap.xml nem érhető el: $BASE_URL/sitemap.xml" >&2; exit 2; }
|
||||
HOME_HTML="$(fetch /hu)" || { echo "❌ A főoldal nem érhető el: $BASE_URL/hu" >&2; exit 2; }
|
||||
|
||||
has_disallow_all=0
|
||||
printf '%s\n' "$ROBOTS" | grep -qiE '^Disallow:[[:space:]]*/[[:space:]]*$' && has_disallow_all=1
|
||||
has_sitemap_ref=0
|
||||
printf '%s\n' "$ROBOTS" | grep -qi '^Sitemap:' && has_sitemap_ref=1
|
||||
has_noindex=0
|
||||
printf '%s' "$HOME_HTML" | grep -qiE '<meta[^>]*name="robots"[^>]*noindex' && has_noindex=1
|
||||
url_count="$(printf '%s' "$SITEMAP" | grep -o '<url>' | wc -l | tr -d ' ')"
|
||||
|
||||
errors=()
|
||||
if [ "$EXPECT" = "indexable" ]; then
|
||||
[ "$has_disallow_all" -eq 0 ] || errors+=("a robots.txt mindent tilt (Disallow: /)")
|
||||
[ "$has_sitemap_ref" -eq 1 ] || errors+=("a robots.txt nem hivatkozik a sitemapre")
|
||||
[ "$has_noindex" -eq 0 ] || errors+=("a főoldalon noindex jelölés van")
|
||||
[ "$url_count" -gt 0 ] || errors+=("a sitemap üres")
|
||||
else
|
||||
[ "$has_disallow_all" -eq 1 ] || errors+=("a robots.txt nem tilt mindent")
|
||||
[ "$has_noindex" -eq 1 ] || errors+=("a főoldalon nincs noindex jelölés")
|
||||
[ "$url_count" -eq 0 ] || errors+=("a sitemap nem üres ($url_count URL)")
|
||||
fi
|
||||
|
||||
if [ "${#errors[@]}" -gt 0 ]; then
|
||||
echo "❌ Indexelhetőség nem az elvárt ($EXPECT) — $BASE_URL:" >&2
|
||||
printf ' - %s\n' "${errors[@]}" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Indexelhetőség rendben ($EXPECT): $BASE_URL (sitemap: $url_count URL)"
|
||||
@@ -0,0 +1,90 @@
|
||||
// MITHOME-127: tests for scripts/check-indexability.sh against a local HTTP
|
||||
// server that impersonates an indexable (production) or blocked (staging) site.
|
||||
const { test, before, after } = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const http = require('node:http')
|
||||
const { spawn } = require('node:child_process')
|
||||
const path = require('node:path')
|
||||
|
||||
const SCRIPT = path.join(__dirname, 'check-indexability.sh')
|
||||
|
||||
const SITES = {
|
||||
indexable: {
|
||||
'/robots.txt': 'User-Agent: *\nAllow: /\nDisallow: /admin\n\nSitemap: https://mozdit.hu/sitemap.xml\n',
|
||||
'/sitemap.xml': '<urlset><url><loc>https://mozdit.hu/hu</loc></url><url><loc>https://mozdit.hu/en</loc></url></urlset>',
|
||||
'/hu': '<html><head><title>mozdIT</title></head><body>ok</body></html>',
|
||||
},
|
||||
blocked: {
|
||||
'/robots.txt': 'User-Agent: *\nDisallow: /\n',
|
||||
'/sitemap.xml': '<urlset></urlset>',
|
||||
'/hu': '<html><head><meta name="robots" content="noindex, nofollow"/></head><body>ok</body></html>',
|
||||
},
|
||||
// production build that wrongly got NEXT_PUBLIC_DEPLOY_ENV=staging for the page only
|
||||
leakyNoindex: {
|
||||
'/robots.txt': 'User-Agent: *\nAllow: /\n\nSitemap: https://mozdit.hu/sitemap.xml\n',
|
||||
'/sitemap.xml': '<urlset><url><loc>https://mozdit.hu/hu</loc></url></urlset>',
|
||||
'/hu': '<html><head><meta name="robots" content="noindex, nofollow"/></head></html>',
|
||||
},
|
||||
}
|
||||
|
||||
let server
|
||||
let origin
|
||||
|
||||
before(async () => {
|
||||
server = http.createServer((req, res) => {
|
||||
const [, site, ...rest] = req.url.split('/')
|
||||
const body = SITES[site]?.['/' + rest.join('/')]
|
||||
res.writeHead(body === undefined ? 404 : 200)
|
||||
res.end(body ?? 'not found')
|
||||
})
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
|
||||
origin = `http://127.0.0.1:${server.address().port}`
|
||||
})
|
||||
|
||||
after(() => server.close())
|
||||
|
||||
function check(site, expect) {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn('bash', [SCRIPT, `${origin}/${site}`, expect])
|
||||
let out = ''
|
||||
child.stdout.on('data', (d) => (out += d))
|
||||
child.stderr.on('data', (d) => (out += d))
|
||||
child.on('close', (code) => resolve({ code, out }))
|
||||
})
|
||||
}
|
||||
|
||||
test('accepts an indexable production site', async () => {
|
||||
const { code, out } = await check('indexable', 'indexable')
|
||||
assert.equal(code, 0, out)
|
||||
assert.match(out, /sitemap: 2 URL/)
|
||||
})
|
||||
|
||||
test('accepts a blocked staging site', async () => {
|
||||
assert.equal((await check('blocked', 'blocked')).code, 0)
|
||||
})
|
||||
|
||||
test('fails when production is blocked, listing every problem', async () => {
|
||||
const { code, out } = await check('blocked', 'indexable')
|
||||
assert.equal(code, 1)
|
||||
assert.match(out, /mindent tilt/)
|
||||
assert.match(out, /noindex/)
|
||||
assert.match(out, /sitemap üres/)
|
||||
})
|
||||
|
||||
test('fails on a stray noindex even if robots.txt looks fine', async () => {
|
||||
const { code, out } = await check('leakyNoindex', 'indexable')
|
||||
assert.equal(code, 1)
|
||||
assert.match(out, /noindex/)
|
||||
})
|
||||
|
||||
test('fails when staging became indexable', async () => {
|
||||
const { code } = await check('indexable', 'blocked')
|
||||
assert.equal(code, 1)
|
||||
})
|
||||
|
||||
test('returns 2 for bad usage or an unreachable site', async () => {
|
||||
assert.equal((await check('indexable', 'maybe')).code, 2)
|
||||
const missing = await check('missing', 'indexable')
|
||||
assert.equal(missing.code, 2, missing.out)
|
||||
assert.match(missing.out, /robots\.txt nem érhető el/)
|
||||
})
|
||||
@@ -40,6 +40,7 @@ run "content: séma-validáció (minden JSON)" node "${ROOT}/scripts/test-conten
|
||||
|
||||
# ── Infra ────────────────────────────────────────────────────────────────────
|
||||
run "plane: sync unit tesztek" node --test "${ROOT}/scripts/plane/plane-sync.test.js"
|
||||
run "infra: indexelhetőségi őr (MITHOME-127)" node --test "${ROOT}/scripts/check-indexability.test.js"
|
||||
|
||||
# ── Összegzés ────────────────────────────────────────────────────────────────
|
||||
printf '\n────────────────────────────────────────\n'
|
||||
|
||||
Reference in New Issue
Block a user