From d98cc41146bbd8a0afa2a84d3e9d6f31574b6dae Mon Sep 17 00:00:00 2001 From: glary-bot Date: Thu, 14 May 2026 07:03:44 +0000 Subject: [PATCH] fix(routes): make affiliateTerms locale-invariant in getRoutes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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().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 // 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. --- .../src/components/legal/legalSections.test.ts | 9 +++++++++ apps/website/src/config/routes.ts | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/website/src/components/legal/legalSections.test.ts b/apps/website/src/components/legal/legalSections.test.ts index e937fb49e0..719406e85b 100644 --- a/apps/website/src/components/legal/legalSections.test.ts +++ b/apps/website/src/components/legal/legalSections.test.ts @@ -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') + }) }) diff --git a/apps/website/src/config/routes.ts b/apps/website/src/config/routes.ts index 9cf70157f2..994ee654eb 100644 --- a/apps/website/src/config/routes.ts +++ b/apps/website/src/config/routes.ts @@ -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() must not prefix them — emitting +// /zh-CN/ 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(['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 }