From 1e93d30d1fa3fd65c03db055dba8c2c4b8e3d65e Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:53:42 +0900 Subject: [PATCH] refactor(platform): drop the .tsx re-export, move CI-only policies, derive message locales (Q-6.9-12) - Delete src/features/reference-feature/presentation/reference-feature-runtime.tsx: it only re-exported the same-named .ts and nothing imported it by the .tsx path. - Move promotion-readiness.ts and performance-budgets.ts from src/application/policies to scripts/lib: only scripts and their unit tests import them. Imports updated in 5 scripts and 2 tests. config/testing/risk-coverage.json lists only src modules, so their two criticalModules/highRiskPaths entries are removed; the synthetic 14-file summary fixture now names two other existing src modules. - installed-feature-messages.ts composes one catalog per locale the installed features declare (composeInstalledMessageCatalogs) instead of a fixed ko-KR/en-US list that silently dropped other catalogs. The exported type still maps each declared locale to its exact key set. Verified: tests/unit/installed-feature-messages.test.ts (ko-KR/en-US content pinned first; derived-locale and duplicate-key cases RED before); app typecheck also passes with a zero-feature generated index; all gates PASS; check:ci PASS; check-bundle resolves the moved module (stops later on the absent artifacts/performance/bundle.json). Co-Authored-By: Claude Opus 5.5 --- config/testing/risk-coverage.json | 22 -------- scripts/check-bundle.ts | 2 +- scripts/check-ci-contract.ts | 2 +- scripts/collect-web-vitals-evidence.ts | 2 +- scripts/contracts/ci-gates.ts | 2 +- .../lib}/performance-budgets.ts | 0 .../lib}/promotion-readiness.ts | 0 scripts/test-performance.ts | 2 +- src/features/installed-feature-messages.ts | 53 +++++++++++++------ .../reference-feature-runtime.tsx | 5 -- .../coverage/repository-omission.json | 4 +- tests/unit/installed-feature-messages.test.ts | 36 +++++++++++++ tests/unit/performance-budgets.test.ts | 2 +- tests/unit/promotion-readiness.test.ts | 2 +- 14 files changed, 81 insertions(+), 53 deletions(-) rename {src/application/policies => scripts/lib}/performance-budgets.ts (100%) rename {src/application/policies => scripts/lib}/promotion-readiness.ts (100%) delete mode 100644 src/features/reference-feature/presentation/reference-feature-runtime.tsx create mode 100644 tests/unit/installed-feature-messages.test.ts diff --git a/config/testing/risk-coverage.json b/config/testing/risk-coverage.json index 11cbb039..f3b5eb7b 100644 --- a/config/testing/risk-coverage.json +++ b/config/testing/risk-coverage.json @@ -119,26 +119,6 @@ "branches": 75 } }, - { - "path": "src/application/policies/performance-budgets.ts", - "owner": "application-policy", - "minimum": { - "lines": 80, - "statements": 80, - "functions": 80, - "branches": 40 - } - }, - { - "path": "src/application/policies/promotion-readiness.ts", - "owner": "release-runtime", - "minimum": { - "lines": 95, - "statements": 95, - "functions": 95, - "branches": 95 - } - }, { "path": "src/application/use-cases/decide-chunk-recovery.ts", "owner": "application-runtime", @@ -212,8 +192,6 @@ "src/adapters/telemetry/best-effort-telemetry.ts", "src/application/create-application.ts", "src/contracts/compatibility.ts", - "src/application/policies/performance-budgets.ts", - "src/application/policies/promotion-readiness.ts", "src/application/use-cases/decide-chunk-recovery.ts", "src/bootstrap/load-release-manifest.ts", "src/bootstrap/read-bounded-boot-json.ts", diff --git a/scripts/check-bundle.ts b/scripts/check-bundle.ts index a3117630..64223b20 100644 --- a/scripts/check-bundle.ts +++ b/scripts/check-bundle.ts @@ -1,6 +1,6 @@ import { readFile } from "node:fs/promises"; -import { evaluateBundleBudget } from "../src/application/policies/performance-budgets.ts"; +import { evaluateBundleBudget } from "./lib/performance-budgets.ts"; import { bundleOutputInventoryArtifactSchema, bundlePerformanceArtifactSchema, diff --git a/scripts/check-ci-contract.ts b/scripts/check-ci-contract.ts index 23768272..9eacfd0b 100644 --- a/scripts/check-ci-contract.ts +++ b/scripts/check-ci-contract.ts @@ -5,7 +5,7 @@ import { evaluatePromotionReadiness, PROMOTION_FORMULA, type GateResult, -} from "../src/application/policies/promotion-readiness.ts"; +} from "./lib/promotion-readiness.ts"; import { loadCiGateContract, indexCiGateContract, diff --git a/scripts/collect-web-vitals-evidence.ts b/scripts/collect-web-vitals-evidence.ts index 1935e371..7f1a90b7 100644 --- a/scripts/collect-web-vitals-evidence.ts +++ b/scripts/collect-web-vitals-evidence.ts @@ -3,7 +3,7 @@ import { mkdir, readFile } from "node:fs/promises"; import { evaluateFieldBudget, percentile75, -} from "../src/application/policies/performance-budgets.ts"; +} from "./lib/performance-budgets.ts"; import { fieldWebVitalsArtifactSchema } from "./contracts/release-artifacts.ts"; import { validateFieldEvidenceInput } from "./lib/field-vitals-evidence.ts"; import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts"; diff --git a/scripts/contracts/ci-gates.ts b/scripts/contracts/ci-gates.ts index 3443ca9c..d5557b45 100644 --- a/scripts/contracts/ci-gates.ts +++ b/scripts/contracts/ci-gates.ts @@ -4,7 +4,7 @@ import path from "node:path"; import { z } from "zod"; -import { PROMOTION_FORMULA } from "../../src/application/policies/promotion-readiness.ts"; +import { PROMOTION_FORMULA } from "../lib/promotion-readiness.ts"; import { RELEASE_CANDIDATE_EVIDENCE_PATHS, RELEASE_CANDIDATE_MANIFEST_PATH, diff --git a/src/application/policies/performance-budgets.ts b/scripts/lib/performance-budgets.ts similarity index 100% rename from src/application/policies/performance-budgets.ts rename to scripts/lib/performance-budgets.ts diff --git a/src/application/policies/promotion-readiness.ts b/scripts/lib/promotion-readiness.ts similarity index 100% rename from src/application/policies/promotion-readiness.ts rename to scripts/lib/promotion-readiness.ts diff --git a/scripts/test-performance.ts b/scripts/test-performance.ts index 2eb3e7a5..00547c8a 100644 --- a/scripts/test-performance.ts +++ b/scripts/test-performance.ts @@ -5,7 +5,7 @@ import process from "node:process"; import { chromium } from "@playwright/test"; -import { evaluateLabBudget } from "../src/application/policies/performance-budgets.ts"; +import { evaluateLabBudget } from "./lib/performance-budgets.ts"; import { ROUTE_REGISTRY } from "../src/features/installed-feature-contracts.ts"; import { labPerformanceArtifactSchema } from "./contracts/release-artifacts.ts"; import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts"; diff --git a/src/features/installed-feature-messages.ts b/src/features/installed-feature-messages.ts index b6aa5763..ecd72782 100644 --- a/src/features/installed-feature-messages.ts +++ b/src/features/installed-feature-messages.ts @@ -1,3 +1,4 @@ +import type { FeatureMessageCatalogs } from "./feature-module.ts"; import { INSTALLED_PRODUCT_FEATURE_MODULES } from "./installed-product-manifest.ts"; type InstalledModule = (typeof INSTALLED_PRODUCT_FEATURE_MODULES)[number]; @@ -13,26 +14,44 @@ type LocaleCatalog = UnionToIntersection< : Readonly> : never >; +type InstalledLocale = InstalledModule extends unknown + ? Extract + : never; -function composeLocale(locale: Locale): LocaleCatalog { - const result: Record = {}; - for (const module of INSTALLED_PRODUCT_FEATURE_MODULES) { - const catalogs = module.messages as Readonly< - Record>> - >; - const catalog = catalogs[locale]; - if (!catalog) continue; - for (const [key, value] of Object.entries(catalog)) { - if (Object.hasOwn(result, key)) { - throw new TypeError(`Duplicate ${locale} message key: ${key}`); +/** + * Q-6.9-12. One catalog per locale that any installed feature declares. The + * locale list used to be fixed at ko-KR/en-US, so a feature's other catalogs + * were dropped without a word. A key two features define for one locale + * still throws. + */ +export function composeInstalledMessageCatalogs( + modules: readonly Readonly<{ messages: FeatureMessageCatalogs }>[], +): Readonly>>> { + const locales = new Map>(); + for (const module of modules) { + for (const [locale, catalog] of Object.entries(module.messages)) { + let result = locales.get(locale); + if (!result) { + result = {}; + locales.set(locale, result); + } + for (const [key, value] of Object.entries(catalog)) { + if (Object.hasOwn(result, key)) { + throw new TypeError(`Duplicate ${locale} message key: ${key}`); + } + result[key] = value; } - result[key] = value; } } - return Object.freeze(result) as LocaleCatalog; + return Object.freeze( + Object.fromEntries( + [...locales].map(([locale, catalog]) => [locale, Object.freeze(catalog)]), + ), + ); } -export const INSTALLED_MESSAGE_CATALOGS = Object.freeze({ - "ko-KR": composeLocale("ko-KR"), - "en-US": composeLocale("en-US"), -} as const); +export const INSTALLED_MESSAGE_CATALOGS = composeInstalledMessageCatalogs( + INSTALLED_PRODUCT_FEATURE_MODULES, +) as { + readonly [Locale in InstalledLocale]: LocaleCatalog; +}; diff --git a/src/features/reference-feature/presentation/reference-feature-runtime.tsx b/src/features/reference-feature/presentation/reference-feature-runtime.tsx deleted file mode 100644 index 4f9fe72b..00000000 --- a/src/features/reference-feature/presentation/reference-feature-runtime.tsx +++ /dev/null @@ -1,5 +0,0 @@ -export { - REFERENCE_FEATURE_ROUTE_CODECS, - REFERENCE_FEATURE_ROUTE_RUNTIME, - REFERENCE_FEATURE_RUNTIME_CONTRIBUTION, -} from "./reference-feature-runtime.ts"; diff --git a/tests/fixtures/coverage/repository-omission.json b/tests/fixtures/coverage/repository-omission.json index ba04a728..ae2b8436 100644 --- a/tests/fixtures/coverage/repository-omission.json +++ b/tests/fixtures/coverage/repository-omission.json @@ -38,10 +38,10 @@ "src/contracts/compatibility.ts": { "lines": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "statements": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "branches": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 } }, - "src/application/policies/performance-budgets.ts": { + "src/bootstrap/load-release-manifest.ts": { "lines": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "statements": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "branches": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 } }, - "src/application/policies/promotion-readiness.ts": { + "src/bootstrap/read-bounded-boot-json.ts": { "lines": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "statements": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "functions": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 }, "branches": { "total": 1, "covered": 1, "skipped": 0, "pct": 100 } }, "src/application/use-cases/decide-chunk-recovery.ts": { diff --git a/tests/unit/installed-feature-messages.test.ts b/tests/unit/installed-feature-messages.test.ts new file mode 100644 index 00000000..b8e5ac18 --- /dev/null +++ b/tests/unit/installed-feature-messages.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from "vitest"; + +import { + composeInstalledMessageCatalogs, + INSTALLED_MESSAGE_CATALOGS, +} from "../../src/features/installed-feature-messages.ts"; +import { REFERENCE_MESSAGE_CATALOGS } from "../../src/features/reference-feature/contracts/reference-message-catalog.ts"; + +describe("installed feature message catalogs (Q-6.9-12)", () => { + it("keeps the installed ko-KR and en-US catalogs", () => { + expect(Object.keys(INSTALLED_MESSAGE_CATALOGS).sort()).toEqual(["en-US", "ko-KR"]); + expect(INSTALLED_MESSAGE_CATALOGS["ko-KR"]).toEqual(REFERENCE_MESSAGE_CATALOGS["ko-KR"]); + expect(INSTALLED_MESSAGE_CATALOGS["en-US"]).toEqual(REFERENCE_MESSAGE_CATALOGS["en-US"]); + }); + + it("composes every locale a feature declares, not a fixed list", () => { + const catalogs = composeInstalledMessageCatalogs([ + { messages: { "ko-KR": { a: "가" }, "ja-JP": { a: "あ" } } }, + { messages: { "ko-KR": { b: "나" } } }, + ]); + expect(catalogs).toEqual({ + "ko-KR": { a: "가", b: "나" }, + "ja-JP": { a: "あ" }, + }); + expect(Object.isFrozen(catalogs["ko-KR"])).toBe(true); + }); + + it("rejects a key two features define for the same locale", () => { + expect(() => + composeInstalledMessageCatalogs([ + { messages: { "en-US": { a: "A" } } }, + { messages: { "en-US": { a: "B" } } }, + ]), + ).toThrow("Duplicate en-US message key: a"); + }); +}); diff --git a/tests/unit/performance-budgets.test.ts b/tests/unit/performance-budgets.test.ts index 4e3ac585..8d33d5d8 100644 --- a/tests/unit/performance-budgets.test.ts +++ b/tests/unit/performance-budgets.test.ts @@ -5,7 +5,7 @@ import { evaluateFieldBudget, evaluateLabBudget, percentile75, -} from "../../src/application/policies/performance-budgets.ts"; +} from "../../scripts/lib/performance-budgets.ts"; describe("performance budgets", () => { it("rejects initial and lazy JavaScript above their named limits", () => { diff --git a/tests/unit/promotion-readiness.test.ts b/tests/unit/promotion-readiness.test.ts index 9b5e3631..0984ae69 100644 --- a/tests/unit/promotion-readiness.test.ts +++ b/tests/unit/promotion-readiness.test.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"; import { evaluatePromotionReadiness, PROMOTION_FORMULA, -} from "../../src/application/policies/promotion-readiness.ts"; +} from "../../scripts/lib/promotion-readiness.ts"; const allGateIds = Object.values(PROMOTION_FORMULA).flat(); type GateResults = Parameters[0];