문제 기능 하나가 같은 HTTP API를 두 번 적는다. *-api-contract.ts의 V2 행 (defineRestOperation)은 check:registries(FE-REG-API)가 검사하는 선언이고, contract contribution의 V3 descriptor가 실제로 실행된다. 둘이 어긋나지 않게 http-operation-v2-v3-parity 테스트를 따로 둔다. 048f490으로 V2 클라이언트가 없어져 V2 행을 읽는 실행 코드는 없고, 검사만 남은 두 번째 사본이다. V2 행을 위한 기능별 runtimeSchemas·mappers 레지스트리와 V2 보안 프로필 해석 (resolveRestSecurityProfiles)도 같이 남아 있다. 사용자 지시: 최신 경로 하나만 남기고, 레지스트리 기준선 재승인을 승인했다. 고른 방법 - src/contracts/api-operations.ts를 projectApiOperationRows 하나로 바꿨다. 조립된 contribution의 descriptor마다 operationId, featureId, method, path, authProfileId, retrySemantics, requestBody, responseBody, responseEnvelope, request/response/problemSchema(검증기 schemaId) 행을 만든다. FE-REG-API는 같은 export(API_OPERATIONS)를 읽고, governance 정의를 이 필드로 바꿨다. requestSchema·responseSchema는 그대로 FE-REG-SCHEMA를 참조한다. - FeatureRuntime은 apiContract 대신 schemas(FE-REG-SCHEMA 행)만 받는다. installed-feature-runtime-registries는 schemas로 스키마 레지스트리를 만들고 FE-REG-API 행을 descriptor에서 뽑는다. RUNTIME_SCHEMA_CODECS, MAPPER_REGISTRY, REST_PROFILE_BINDINGS_VALID, API_RUNTIME_BINDINGS_VALID를 지웠다. - realtime snapshot 바인딩은 ApiOperationRow를 받고 method GET과 retrySemantics SAFE·IDEMPOTENT를 본다(V2의 contractVersion·semantics· replayPolicy 대신). - rest-profiles.ts에서 V2 행용 provider·CSRF 프로필 해석을 지웠다. V3는 조립 때 auth profile을 검사하고 자격증명 헤더를 프로필로 거른다. - 참조 기능: reference-api-contract.ts를 reference-schema-metadata.ts로 바꾸고(스키마 행만), V2 runtime codec·operation mapper·레지스트리 mapper를 지웠다. V3 descriptor가 쓰지 않는 NoRequest 스키마 행도 지웠다. - create:feature: <base>-api-contract.ts 대신 <base>-schema-metadata.ts를 만든다. codec·mapper 레지스트리 행과 그 테스트를 만들지 않는다. - 레지스트리 기준선을 update:registry-baseline으로 다시 만들고 승인했다 (digest 16f72742…, 승인자 DongHyeonka, 이유에 사용자 승인을 적음). - 매뉴얼 01·02·reference, starter-experience, 계약 문서의 V2 설명을 지웠다. 버린 대안 - V2 행을 남기고 V3에서 생성하기: 생성 단계와 생성물이 하나 더 생긴다. 행은 실행되지 않으므로 메모리에서 뽑아 검사하면 충분하다. - 스키마 메타데이터(FE-REG-SCHEMA 행)도 검증기에서 뽑기: boundary· unknownFieldPolicy·owner는 검증기에 없고, 라우트 스키마도 같은 레지스트리를 쓴다. 이 행은 V2가 아니라 스키마 레지스트리라 남겼다. 위험·한계 - BREAKING: FeatureRuntime 모양, contracts·rest-profiles·loaded-feature-runtimes 의 이름이 바뀌거나 없어졌다. memento-frontend의 memento-web이 V2 행을 쓴다. 옮기는 법은 CHANGELOG에 적는다. - V2 보안 프로필 일관성 검사(auth "none"과 ANONYMOUS, 쿠키 프로필의 CSRF 모드)가 사라졌다. V3 descriptor에는 그 칸이 없다. - BoundedPollOperationContract(realtime polling recipe)는 contractVersion: 2 필드를 갖지만 자체 계약이라 바꾸지 않았다. 검증 - check:types, lint, check:architecture, check:registries(11 registries PASS, compatibility=none), check:ci, check:diagnostics, check:adapter-inventory, verify:documentation 통과. - test:unit 2,566(새 tests/unit/api-operation-rows.test.ts 3건 포함), test:integration 114, test:component 245, test:contract 23, test:runtime-schema 56, tests/features 99 통과. - tests/unit/second-api-feature-registries.test.ts: V3 descriptor만 가진 두 번째 기능을 복사본에 넣으면 기준선을 고치지 않고 check:registries가 통과한다. - check:bundle 통과. 초기 JS 201,598 → 200,911 B. - test:feature-scaffold 16개, test:sample-removal 23개 검사 통과. BREAKING CHANGE: FeatureRuntime이 apiContract 대신 schemas를 받는다. defineRestOperation, ApiOperation, RestOperationV2, composeApiOperations, validateApiRuntimeBindings, getApiOperation, contracts의 API_OPERATIONS, createRestProviderProfile, RestProviderProfile, resolveRestSecurityProfiles, validateRestProfileBindings, REST_CSRF_PROFILES, RestCsrfProfile, loaded-feature-runtimes의 RUNTIME_SCHEMA_CODECS, MAPPER_REGISTRY, REST_PROFILE_BINDINGS_VALID, API_RUNTIME_BINDINGS_VALID가 없어졌다. 기능은 operation을 contract contribution에만 적고, schemas 행을 feature-runtime에 넘긴다.
242 lines
8.2 KiB
TypeScript
242 lines
8.2 KiB
TypeScript
import { type ComponentType, lazy, useEffect, useState } from "react";
|
|
import { type RouteObject, useSearchParams } from "react-router-dom";
|
|
import { z } from "zod";
|
|
|
|
import { defineBoundedContextModule } from "../../src/contexts/bounded-context-module.ts";
|
|
import { defineFeatureModule } from "../../src/features/feature-module.ts";
|
|
// Not the design-system barrel: it reaches the installed catalogs, whose
|
|
// generated index the tests mock with this module, and the mock would wait on
|
|
// itself.
|
|
import { PageHeader } from "../../src/presentation/components/page-header.tsx";
|
|
import { useApplicationRuntime } from "../../src/presentation/providers/application-provider.tsx";
|
|
|
|
/**
|
|
* A test-only product feature for platform tests that need routes and pages of
|
|
* their own: routes that require a session and parse a search codec, public
|
|
* pages in the primary navigation, and pages that fail to render. Those tests
|
|
* install it by mocking the generated indexes, so they depend neither on the
|
|
* removable sample feature (FE-GATE-020) nor on the starter screens a product
|
|
* replaces (`/`, `/examples/*`; 0929/10-02):
|
|
*
|
|
* vi.mock("../../src/.generated/product-feature-index.ts", async () => ({
|
|
* DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"],
|
|
* PRODUCT_FEATURE_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE],
|
|
* }));
|
|
* vi.mock("../../src/.generated/product-context-index.ts", async () => ({
|
|
* PRODUCT_CONTEXT_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_CONTEXT_MODULE],
|
|
* }));
|
|
*/
|
|
export const FIXTURE_FEATURE_ID = "fixture-feature";
|
|
|
|
function fixtureRoute(
|
|
routeId: string,
|
|
path: string,
|
|
searchSchema: string | null,
|
|
chunkId: string,
|
|
) {
|
|
return Object.freeze({
|
|
routeId,
|
|
path,
|
|
paramsSchema: null,
|
|
searchSchema,
|
|
access: "session-required",
|
|
loadingSurface: "fixture-page",
|
|
errorSurface: "feature-boundary",
|
|
chunkId,
|
|
title: routeId,
|
|
navigationLabel: null,
|
|
navigationOrder: null,
|
|
});
|
|
}
|
|
|
|
/** A public page like the starter pages: route boundary, optional menu entry. */
|
|
function publicFixtureRoute(
|
|
routeId: string,
|
|
path: string,
|
|
chunkId: string,
|
|
navigationOrder: number | null,
|
|
) {
|
|
return Object.freeze({
|
|
...fixtureRoute(routeId, path, null, chunkId),
|
|
access: "public" as const,
|
|
errorSurface: "route-boundary",
|
|
navigationLabel: navigationOrder === null ? null : routeId,
|
|
navigationOrder,
|
|
});
|
|
}
|
|
|
|
const FIXTURE_ROUTES = Object.freeze({
|
|
FIXTURE_ITEMS: fixtureRoute("FIXTURE_ITEMS", "/fixture/items", "FixtureItemsQuery", "route-fixture-items"),
|
|
FIXTURE_ITEM_STATUS: fixtureRoute("FIXTURE_ITEM_STATUS", "/fixture/items/status", null, "route-fixture-item-status"),
|
|
FIXTURE_ITEM_FORM: fixtureRoute("FIXTURE_ITEM_FORM", "/fixture/items/new", null, "route-fixture-item-form"),
|
|
FIXTURE_FIRST_PAGE: publicFixtureRoute("FIXTURE_FIRST_PAGE", "/fixture/first", "route-fixture-first", 900),
|
|
FIXTURE_SECOND_PAGE: publicFixtureRoute("FIXTURE_SECOND_PAGE", "/fixture/second", "route-fixture-second", 910),
|
|
FIXTURE_OFFLINE_PAGE: publicFixtureRoute("FIXTURE_OFFLINE_PAGE", "/fixture/offline", "route-fixture-offline", null),
|
|
FIXTURE_BROKEN_PAGE: publicFixtureRoute("FIXTURE_BROKEN_PAGE", "/fixture/broken", "route-fixture-broken", null),
|
|
});
|
|
|
|
type FixtureRouteId = keyof typeof FIXTURE_ROUTES;
|
|
|
|
const FIXTURE_TITLES: Readonly<Record<FixtureRouteId, string>> = {
|
|
FIXTURE_ITEMS: "Fixture items",
|
|
FIXTURE_ITEM_STATUS: "Fixture item status",
|
|
FIXTURE_ITEM_FORM: "Create fixture item",
|
|
FIXTURE_FIRST_PAGE: "Fixture first page",
|
|
FIXTURE_SECOND_PAGE: "Fixture second page",
|
|
FIXTURE_OFFLINE_PAGE: "Fixture offline page",
|
|
FIXTURE_BROKEN_PAGE: "Fixture broken page",
|
|
};
|
|
|
|
const FIXTURE_MESSAGES = Object.freeze(
|
|
Object.fromEntries(
|
|
Object.entries(FIXTURE_TITLES).flatMap(([routeId, title]) => [
|
|
[`route.${routeId}.title`, title],
|
|
[`route.${routeId}.navigation`, title],
|
|
]),
|
|
),
|
|
);
|
|
|
|
export const FIXTURE_FEATURE_MODULE = defineFeatureModule({
|
|
id: FIXTURE_FEATURE_ID,
|
|
contracts: Object.freeze({
|
|
featureId: FIXTURE_FEATURE_ID,
|
|
routes: FIXTURE_ROUTES,
|
|
routeRuntimeContracts: Object.freeze(
|
|
Object.fromEntries(
|
|
Object.values(FIXTURE_ROUTES).map((route) => [
|
|
route.routeId,
|
|
Object.freeze({
|
|
routeId: route.routeId,
|
|
moduleId: `${route.chunkId}-page`,
|
|
paramsCodec: "none",
|
|
searchCodec: route.searchSchema ?? "none",
|
|
}),
|
|
]),
|
|
),
|
|
),
|
|
invalidation: Object.freeze({ topics: [], namespaces: [], edges: [] }),
|
|
topicVersions: Object.freeze([]),
|
|
contractPackages: Object.freeze([]),
|
|
}),
|
|
routes: FIXTURE_ROUTES,
|
|
messages: Object.freeze({ "ko-KR": FIXTURE_MESSAGES, "en-US": FIXTURE_MESSAGES }),
|
|
loadRuntime: async () =>
|
|
Object.freeze({
|
|
featureId: FIXTURE_FEATURE_ID,
|
|
schemas: Object.freeze({}),
|
|
adapters: Object.freeze([]),
|
|
contractContributions: Object.freeze([]),
|
|
}),
|
|
});
|
|
|
|
// 15-01. Route codecs travel on the context route handle, like the sample's.
|
|
const FIXTURE_ROUTE_CODECS = Object.freeze({
|
|
FixtureItemsQuery: z.object({
|
|
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
}),
|
|
});
|
|
|
|
/** A filter bound to the URL query, the way a product list screen keeps it. */
|
|
function FixturePage() {
|
|
const [search, setSearch] = useSearchParams();
|
|
return (
|
|
<>
|
|
<p>Fixture page</p>
|
|
<label>
|
|
Fixture limit
|
|
<select
|
|
value={search.get("limit") ?? "20"}
|
|
onChange={(event) => setSearch({ limit: event.target.value })}
|
|
>
|
|
<option value="20">20</option>
|
|
<option value="50">50</option>
|
|
</select>
|
|
</label>
|
|
</>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* A lazily loaded page that opens with its heading and shows the release the
|
|
* runtime resolved, the way a product page does. Lazy, so a first visit
|
|
* suspends on the route loading surface and a later visit renders at once.
|
|
*/
|
|
function titledPage(title: string): ComponentType {
|
|
return lazy(async () => ({
|
|
default: function FixtureTitledPage() {
|
|
const runtime = useApplicationRuntime();
|
|
const [release, setRelease] = useState<string | null>(null);
|
|
useEffect(() => {
|
|
let active = true;
|
|
runtime.getReleaseSummary().then(
|
|
(summary) => {
|
|
if (active) {
|
|
setRelease(`Fixture release ${summary.buildId} · ${summary.releaseId}`);
|
|
}
|
|
},
|
|
() => {},
|
|
);
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [runtime]);
|
|
return (
|
|
<section className="ui-page">
|
|
<PageHeader title={title} />
|
|
{release === null ? null : <p>{release}</p>}
|
|
</section>
|
|
);
|
|
},
|
|
}));
|
|
}
|
|
|
|
/** A route chunk the network could not deliver: the rejection rethrows on every render. */
|
|
function OfflineChunkPage(): never {
|
|
throw new TypeError(
|
|
"Failed to fetch dynamically imported module: /assets/fixture-offline.js",
|
|
);
|
|
}
|
|
|
|
/** A route page with a programmer defect. */
|
|
function BrokenPage(): never {
|
|
throw new Error("ordinary render defect");
|
|
}
|
|
|
|
const FIXTURE_PAGES: Readonly<Record<FixtureRouteId, ComponentType>> = {
|
|
FIXTURE_ITEMS: FixturePage,
|
|
FIXTURE_ITEM_STATUS: FixturePage,
|
|
FIXTURE_ITEM_FORM: FixturePage,
|
|
FIXTURE_FIRST_PAGE: titledPage(FIXTURE_TITLES.FIXTURE_FIRST_PAGE),
|
|
FIXTURE_SECOND_PAGE: titledPage(FIXTURE_TITLES.FIXTURE_SECOND_PAGE),
|
|
FIXTURE_OFFLINE_PAGE: OfflineChunkPage,
|
|
FIXTURE_BROKEN_PAGE: BrokenPage,
|
|
};
|
|
|
|
export const FIXTURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze(
|
|
(Object.keys(FIXTURE_ROUTES) as FixtureRouteId[]).map((routeId) => {
|
|
const route = FIXTURE_ROUTES[routeId];
|
|
return Object.freeze({
|
|
id: route.routeId,
|
|
path: route.path,
|
|
handle: Object.freeze({
|
|
routeId: route.routeId,
|
|
runtime: Object.freeze({
|
|
moduleId: `${route.chunkId}-page`,
|
|
Component: FIXTURE_PAGES[routeId],
|
|
}),
|
|
codecs: FIXTURE_ROUTE_CODECS,
|
|
}),
|
|
});
|
|
}),
|
|
);
|
|
|
|
export const FIXTURE_CONTEXT_MODULE = defineBoundedContextModule({
|
|
id: "fixture-context",
|
|
features: [FIXTURE_FEATURE_MODULE],
|
|
budget: { maxFeatures: 1 },
|
|
route: {
|
|
path: "fixture/*",
|
|
loadRoutes: async () => FIXTURE_CONTEXT_ROUTES,
|
|
},
|
|
});
|