feat: the route report sends the noindex static paths (tracer)
- noindexStaticRoutes: requiresAuth, noindex/none seo.robots and static
pages under seo.noindexRoutes, i18n copies included, never patterns or
the layer's HTML sitemap pages (G1, gap-2 contract)
- #seo-routes exports noindexPaths; routeReportBody(paths, noindex) answers
{routes, noindex} with the same limits and keeps the JSON body within the
older plugin's 4,113,024 bytes, dropping noindex entries first
- smoke grammar noindex= and lacksnoindex=; README carries the contract
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { htmlSitemapOption, paginationOption } from '../lib/options.ts'
|
||||
import { localeCopySuffixes, pageMetaRobots, robotsNoindex, routePatterns, routesTemplate, staticRoutes } from '../lib/routes.ts'
|
||||
import { localeCopySuffixes, noindexStaticRoutes, pageMetaRobots, robotsNoindex, routePatterns, routesTemplate, staticRoutes } from '../lib/routes.ts'
|
||||
import { DRIFT_PREFIX, driftWarnings, routeServes } from '../server/lib/drift.ts'
|
||||
import { ROUTE_REPORT_MAX_ROUTES, routeReportBody, routeReportOutcome } from '../server/lib/routeReport.ts'
|
||||
import { ROUTE_REPORT_MAX_BODY, ROUTE_REPORT_MAX_ROUTES, routeReportBody, routeReportOutcome } from '../server/lib/routeReport.ts'
|
||||
|
||||
const pages = [
|
||||
{ path: '/', name: 'index' },
|
||||
@@ -46,15 +46,87 @@ test('routePatterns: page paths as patterns, catch-alls marked', () => {
|
||||
assert.equal(new Set(out.map((p) => p.pattern)).size, out.length)
|
||||
})
|
||||
|
||||
test('routesTemplate: an ES module with both lists', () => {
|
||||
const src = routesTemplate(['/'], [{ pattern: '/', catchAll: false }])
|
||||
test('routesTemplate: an ES module with the three lists', () => {
|
||||
const src = routesTemplate(['/'], [{ pattern: '/', catchAll: false }], ['/konto'])
|
||||
assert.match(src, /export const staticRoutes = \["\/"\]/)
|
||||
assert.match(src, /export const routePatterns = \[\{"pattern":"\/","catchAll":false\}\]/)
|
||||
assert.match(src, /export const noindexPaths = \["\/konto"\]/)
|
||||
assert.match(routesTemplate([], []), /export const noindexPaths = \[\]/)
|
||||
})
|
||||
|
||||
test('routeReportBody: within the plugin limits', () => {
|
||||
test('noindexStaticRoutes: the static paths the build serves noindex (G1, gap-2 contract)', () => {
|
||||
const out = noindexStaticRoutes(pages, ['/prywatne/**'])
|
||||
// requiresAuth, a noindex seo.robots and a static page under a noindex pattern
|
||||
assert.deepEqual(out, ['/konto', '/prywatne', '/szkic'])
|
||||
// never an ordinary page, a page with parameters, a catch-all or the layer's sitemap page
|
||||
for (const p of ['/', '/blog', '/otwarty', '/posts/:slug()', '/:slug(.*)*', '/mapa-strony']) assert.ok(!out.includes(p), p)
|
||||
// never a path the route report lists as indexable
|
||||
const indexable = staticRoutes(pages, ['/prywatne/**'])
|
||||
assert.deepEqual(out.filter((p) => indexable.includes(p)), [])
|
||||
})
|
||||
|
||||
test('noindexStaticRoutes: client-only noindex pages kept, patterns never sent', () => {
|
||||
const list = [
|
||||
{ path: '/panel', name: 'panel', mode: 'client', meta: { requiresAuth: true } },
|
||||
{ path: '/p/:id', name: 'p-id', meta: { requiresAuth: true } },
|
||||
{ path: '/p/**', name: 'p-all' },
|
||||
{ path: '/none', name: 'none', meta: { seo: { robots: 'none' } } },
|
||||
]
|
||||
assert.deepEqual(noindexStaticRoutes(list, ['/p/**']), ['/none', '/panel'])
|
||||
})
|
||||
|
||||
test('noindexStaticRoutes: the i18n copies of a noindex page are listed with their prefix, sorted', () => {
|
||||
const localized = [
|
||||
{ path: '/', name: 'index___en' },
|
||||
{ path: '/pl', name: 'index___pl' },
|
||||
{ path: '/konto', name: 'konto___en', meta: { requiresAuth: true } },
|
||||
{ path: '/pl/konto', name: 'konto___pl', meta: { requiresAuth: true } },
|
||||
{ path: '/szkic', name: 'szkic___en', meta: { seo: { robots: 'noindex, follow' } } },
|
||||
{ path: '/pl/szkic', name: 'szkic___pl', meta: { seo: { robots: 'noindex, follow' } } },
|
||||
{ path: '/sitemap', name: 'seo-sitemap-en___en' },
|
||||
]
|
||||
assert.deepEqual(noindexStaticRoutes(localized, []), ['/konto', '/pl/konto', '/pl/szkic', '/szkic'])
|
||||
})
|
||||
|
||||
test('routeReportBody: within the plugin limits, both lists', () => {
|
||||
assert.deepEqual(routeReportBody(['/', '/blog', 'nope', '/' + 'a'.repeat(2048)]).routes, ['/', '/blog'])
|
||||
assert.equal(routeReportBody(Array.from({ length: 2500 }, (_, i) => `/p${i}`)).routes.length, ROUTE_REPORT_MAX_ROUTES)
|
||||
assert.deepEqual(routeReportBody(['/', '/blog'], ['/konto', 'x', '/' + 'b'.repeat(2048), '/szkic']), { routes: ['/', '/blog'], noindex: ['/konto', '/szkic'] })
|
||||
assert.equal(routeReportBody([], Array.from({ length: 2500 }, (_, i) => `/n${i}`)).noindex.length, ROUTE_REPORT_MAX_ROUTES)
|
||||
// always sent, also empty
|
||||
assert.deepEqual(routeReportBody(['/']), { routes: ['/'], noindex: [] })
|
||||
// a path is never in both lists
|
||||
assert.deepEqual(routeReportBody(['/', '/konto'], ['/konto', '/szkic']).noindex, ['/szkic'])
|
||||
})
|
||||
|
||||
const bodyBytes = (b: unknown) => Buffer.byteLength(JSON.stringify(b), 'utf8')
|
||||
|
||||
test('routeReportBody: the JSON body stays within the older plugin limit, noindex dropped first', () => {
|
||||
assert.equal(ROUTE_REPORT_MAX_BODY, 2000 * (2048 + 8) + 1024)
|
||||
assert.equal(ROUTE_REPORT_MAX_BODY, 4_113_024)
|
||||
const routes = Array.from({ length: 2000 }, (_, i) => '/' + String(i).padStart(4, '0') + 'r'.repeat(2043))
|
||||
const noindex = Array.from({ length: 100 }, (_, i) => '/' + String(i).padStart(3, '0') + 'n'.repeat(196))
|
||||
assert.ok(routes.every((p) => Buffer.byteLength(p) === 2048))
|
||||
assert.ok(noindex.every((p) => Buffer.byteLength(p) === 200))
|
||||
const body = routeReportBody(routes, noindex)
|
||||
assert.equal(body.routes.length, 2000)
|
||||
assert.ok(body.noindex.length > 0 && body.noindex.length < 100, String(body.noindex.length))
|
||||
assert.deepEqual(body.noindex, noindex.slice(0, body.noindex.length))
|
||||
assert.ok(bodyBytes(body) <= ROUTE_REPORT_MAX_BODY)
|
||||
// the next noindex entry would not have fitted
|
||||
assert.ok(bodyBytes({ routes: body.routes, noindex: noindex.slice(0, body.noindex.length + 1) }) > ROUTE_REPORT_MAX_BODY)
|
||||
})
|
||||
|
||||
test('routeReportBody: small lists come back whole; routes alone over the limit are cut from the end', () => {
|
||||
assert.deepEqual(routeReportBody(['/a', '/b'], ['/c']), { routes: ['/a', '/b'], noindex: ['/c'] })
|
||||
// 2048 bytes of characters JSON escapes: each path serialises to about twice its size
|
||||
const heavy = Array.from({ length: 2000 }, (_, i) => '/' + String(i).padStart(4, '0') + '"'.repeat(2043))
|
||||
const body = routeReportBody(heavy, ['/konto'])
|
||||
assert.deepEqual(body.noindex, [])
|
||||
assert.ok(body.routes.length > 0 && body.routes.length < 2000, String(body.routes.length))
|
||||
assert.deepEqual(body.routes, heavy.slice(0, body.routes.length))
|
||||
assert.ok(bodyBytes(body) <= ROUTE_REPORT_MAX_BODY)
|
||||
assert.ok(bodyBytes({ routes: heavy.slice(0, body.routes.length + 1), noindex: [] }) > ROUTE_REPORT_MAX_BODY)
|
||||
})
|
||||
|
||||
test('routeReportOutcome: sent, absent, refused or one retry', () => {
|
||||
|
||||
Reference in New Issue
Block a user