fix(routes): make affiliateTerms locale-invariant in getRoutes

Re-prefixing /affiliates/terms with /zh-CN/ would produce a dead link
now that the localized affiliate-terms route has been removed (no
zh-CN page is served from the legal-reviewed English-only document).

Today nothing in apps/website/src or apps/website/e2e calls
getRoutes(<non-en>).affiliateTerms, so this is not user-visible. The
change pre-empts a future regression: most likely from the sibling
affiliates landing PR (#12002), whose footer 'Read the affiliate
program terms' link could route through getRoutes(locale).affiliateTerms
and 404 in zh-CN.

Implementation:
- Add a LOCALE_INVARIANT_ROUTE_KEYS set in src/config/routes.ts and
  skip the /<locale>/ prefix for keys in that set. affiliateTerms is
  the only member today.
- Add a guard test in legalSections.test.ts asserting that both
  getRoutes('en').affiliateTerms and getRoutes('zh-CN').affiliateTerms
  resolve to '/affiliates/terms'. Test count: 35 → 36 passing.

Verification:
- 'pnpm --filter @comfyorg/website typecheck' — 0 errors (90 files)
- 'pnpm --filter @comfyorg/website test:unit' — 36/36 passing
- 'pnpm format:check apps/website' — clean
- 'pnpm exec oxlint apps/website/src apps/website/e2e --quiet' — 0 errors
- 'pnpm --filter @comfyorg/website build' — clean, 52 pages
- 'pnpm exec playwright test affiliates-terms' — 9/9 passing

Addresses the single low-severity finding from an Oracle code review of
the prior two commits on this branch.
This commit is contained in:
glary-bot
2026-05-14 07:03:44 +00:00
committed by Glary-Bot
parent 0fe808ea10
commit d98cc41146
2 changed files with 23 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { getRoutes } from '../../config/routes'
import { hasKey, t, translationKeys } from '../../i18n/translations'
const PREFIX = 'affiliate-terms'
@@ -64,4 +65,12 @@ describe('affiliate terms i18n', () => {
)
expect(leaks).toEqual([])
})
it('exposes affiliate terms at the canonical /affiliates/terms path regardless of locale', () => {
// Guards against re-introducing /zh-CN/affiliates/terms, which would
// serve an unreviewed translation of legal-reviewed copy. See the
// comment on LOCALE_INVARIANT_ROUTE_KEYS in src/config/routes.ts.
expect(getRoutes('en').affiliateTerms).toBe('/affiliates/terms')
expect(getRoutes('zh-CN').affiliateTerms).toBe('/affiliates/terms')
})
})

View File

@@ -20,11 +20,24 @@ const baseRoutes = {
type Routes = typeof baseRoutes
// Routes that are served only at their canonical path regardless of the
// active locale. Localized variants of these routes intentionally do not
// exist, so getRoutes(<non-en>) must not prefix them — emitting
// /zh-CN/<route> would produce a dead link.
//
// affiliateTerms: legal-reviewed English-only document. See the comment
// header in src/pages/affiliates/terms.astro and the affiliate-terms i18n
// block in src/i18n/translations.ts for the reasoning.
const LOCALE_INVARIANT_ROUTE_KEYS = new Set<keyof Routes>(['affiliateTerms'])
export function getRoutes(locale: Locale = 'en'): Routes {
if (locale === 'en') return baseRoutes
const prefix = `/${locale}`
return Object.fromEntries(
Object.entries(baseRoutes).map(([k, v]) => [k, `${prefix}${v}`])
Object.entries(baseRoutes).map(([k, v]) => [
k,
LOCALE_INVARIANT_ROUTE_KEYS.has(k as keyof Routes) ? v : `${prefix}${v}`
])
) as unknown as Routes
}