문제 - 93180f6(합친 커밋d3ddc89)이 초기 JS를 늘렸다. 기능 모양 측정 (scripts/scale/measure-feature-shape-growth.ts) 기준으로 기능 0개가 202,376 → 202,526 B(+150)로, 기능 1개 추가분이 960 → 1,029 B로 늘었다. tests/unit/feature-shape-growth.test.ts의 1 KiB 상한을 넘는다. - 원인은 두 가지다. - 부팅 때 도는 composeContractContributions가 검증기마다 생략 표시를 읽고 목록을 만들었다(feature-platform 청크 +164 B). 이 목록을 쓰는 곳은 플랫폼 개요 화면(lazy 라우트)뿐이다. - 공유 zod-validator.ts가 기능이 두 개가 되면 lazy 청크 하나로 따로 나왔다. 모든 context-routes·feature-runtime import의 preload 목록에 파일 이름이 하나 늘어 boot·feature-declarations 청크가 각각 약 25 B 커졌다. 고른 방법 - 목록 계산을 src/contracts/unvalidated-payload.ts의 listUnvalidatedPayloads(composed)로 옮긴다. 플랫폼 개요 화면만 이것을 import한다. 결정의 뜻(생략한 operation이 조립 결과에서 목록으로 나온다)은 그대로다. 계산 시점만 화면이 열릴 때로 미룬다. ComposedContractContributions.unvalidatedPayloads 필드는 뺀다. - unvalidatedPayload 팩토리도 같은 모듈로 옮긴다. - 조립기의 표시 검사도 뺀다. 이유가 빈 생략은 unvalidatedPayload가 만들 때 거부한다(TypeError). 손으로 붙인 표시는 값이 "NONE"이 아니거나 이유가 없어도 목록에 나온다(화면에는 "이유 없음"). 그래서 생략이 숨지 않는다. external-contract-runtime.ts에는 RuntimeValidator의 선택 타입 필드 2개만 남는다. - vite.config.ts에서 zod-validator.ts를 schema-registry.ts와 같은 lazy 청크로 묶는다. 어댑터를 import하는 곳은 이미 schema-registry 청크를 preload한다. includeDependenciesRecursively: false라서 다른 모듈은 끌려오지 않고, 두 모듈 모두 부팅 그래프 밖이다. 버린 대안 - 조립기에 "NONE + 이유" 검사만 남기기: feature-platform 청크 +57 B gzip. 검사를 팩토리와 목록으로 옮기면 0 B다. 손으로 붙인 잘못된 표시를 부팅 때 거부하지 못하지만, 목록에는 나온다. - zodValidator를 schema-registry.ts 안에 정의: 빌드 설정 없이 같은 결과가 나오지만 결정한 위치(src/contracts/zod-validator.ts)와 다르고, 다음 단계의 기능 생성 명령이 그 경로를 쓴다. - 어댑터를 zod.ts에 두기: zod 입구는 초기 청크라 기능 0개 초기 JS가 는다. 위험·한계 - 조립 결과 타입에서 unvalidatedPayloads 필드가 빠진다. 93180f6 뒤 이 필드를 쓴 코드는 listUnvalidatedPayloads로 바꿔야 한다. repo 안에서는 화면과 테스트만 썼다. - 손으로 만든 잘못된 표시(예: validation: "PARTIAL")는 더 이상 조립에서 거부되지 않는다. 목록에만 나온다. 테스트 2건을 이 동작으로 바꿨다. - 청크 묶음은 빌드 설정에 두 파일 경로를 적는다. 파일 이름을 바꾸면 정규식도 함께 바꿔야 한다. 놓치면 바이트만 늘고 동작은 같다. - 플랫폼 개요 화면을 열면 schema-registry 청크에 어댑터(351 B raw)가 같이 온다. 검증 - 기능 모양 측정(0개 / 1개 추가분, gzip B): - ee81c44(07-03 전): 202,376 / 960 - d3ddc89(07-03 합친 뒤): 202,526 / 1,029 - 목록만 부팅 밖으로: 202,407 / 1,035 - 청크 묶음 추가: 202,424 / 983 - 조립기 검사 제거(이 커밋): 202,371 / 958 - feature-shape-growth.test.ts 6건 통과. - 07-03 테스트 3파일 33건 통과(zod-validator, external-contract-runtime, starter-platform-overview-page). - 회귀: tests/unit·contract·component·runtime-schema·features·platform 270파일 3,203건, tests/integration 12파일 158건(pnpm을 띄우는 security-followup-archive 제외), tests/architecture 7파일 33건 통과. - tsc app·node·test·recipes·web-worker·service-worker 오류 0. 바꾼 파일 eslint 0. 아키텍처 그래프 검사(pnpm 대신 exec stub) 413 모듈 PASS. check-registries PASS(compatibility=none). - 본 빌드 초기 JS gzip 202,371 B(26파일). raw 644,782 B로ee81c44측정과 같다. Refs: docs/reviews/2026-11-01-maturity-review/07-contracts.md 07-03
244 lines
8.5 KiB
TypeScript
244 lines
8.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { composeContractContributions } from "../../src/contracts/external-contract-runtime.ts";
|
|
import { unvalidatedPayload } from "../../src/contracts/unvalidated-payload.ts";
|
|
import { SERVER_STATE_PROFILES } from "../../src/contracts/server-state.ts";
|
|
import { COMPOSED_CONTRACT_CONTRIBUTIONS } from "../../src/features/loaded-feature-runtimes.ts";
|
|
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
|
import { PlatformOverviewPage } from "../../src/presentation/examples/platform-overview-page.tsx";
|
|
import { LocaleProvider } from "../../src/presentation/i18n/index.ts";
|
|
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
|
|
import { createTestApplication } from "../helpers/create-test-application.ts";
|
|
import { TEST_CONTRACT_CONTRIBUTION } from "../helpers/external-contract-fixture.ts";
|
|
import { createRuntimeCapabilitiesStub } from "../helpers/runtime-capabilities-stub.ts";
|
|
|
|
/**
|
|
* A starter screen (0929/10-02): a product that replaces `/examples/platform`
|
|
* deletes this file with it. Platform tests use the test-only feature's pages.
|
|
*
|
|
* The page must stay a projection of the installed registries. Every assertion
|
|
* below derives its expectation from the same registry the page reads, so a
|
|
* template that removes its sample feature still satisfies this suite.
|
|
*/
|
|
|
|
function renderPage() {
|
|
return render(
|
|
<ApplicationProvider application={createTestApplication()}>
|
|
<LocaleProvider>
|
|
<PlatformOverviewPage contracts={COMPOSED_CONTRACT_CONTRIBUTIONS} />
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
);
|
|
}
|
|
|
|
function tableByCaption(caption: string): HTMLElement {
|
|
return screen.getByRole("table", { name: caption });
|
|
}
|
|
|
|
/** A metric is a `dt`/`dd` pair, which carries no ARIA role to query by. */
|
|
function metricByLabel(scope: HTMLElement, label: string): HTMLElement {
|
|
const term = within(scope).getByText(label).closest(".platform-metric");
|
|
if (!(term instanceof HTMLElement)) {
|
|
throw new Error(`No metric is labelled ${label}`);
|
|
}
|
|
return term;
|
|
}
|
|
|
|
describe("platform overview page", () => {
|
|
it("renders one route row per installed route registry entry", () => {
|
|
renderPage();
|
|
|
|
const table = tableByCaption("설치된 라우트 목록");
|
|
const dataRows = within(table).getAllByRole("row").slice(1);
|
|
|
|
expect(dataRows).toHaveLength(Object.keys(ROUTE_REGISTRY).length);
|
|
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
|
expect(
|
|
within(table).getByText(definition.routeId),
|
|
).toBeInTheDocument();
|
|
}
|
|
});
|
|
|
|
it("renders one operation row per installed HTTP contract", () => {
|
|
const operationIds = [
|
|
...COMPOSED_CONTRACT_CONTRIBUTIONS.httpByOperationId.keys(),
|
|
];
|
|
renderPage();
|
|
|
|
if (operationIds.length === 0) {
|
|
expect(
|
|
screen.getByRole("heading", {
|
|
name: "설치된 HTTP 오퍼레이션이 없습니다.",
|
|
}),
|
|
).toBeVisible();
|
|
return;
|
|
}
|
|
|
|
const table = tableByCaption("설치된 HTTP 오퍼레이션");
|
|
expect(within(table).getAllByRole("row").slice(1)).toHaveLength(
|
|
operationIds.length,
|
|
);
|
|
for (const operationId of operationIds) {
|
|
expect(within(table).getByText(operationId)).toBeInTheDocument();
|
|
}
|
|
});
|
|
|
|
// 1101/07-03. A skipped validation is shown, not just composed.
|
|
it("lists the operations that skip runtime validation, with the reason", () => {
|
|
const [listRow, ...rest] = TEST_CONTRACT_CONTRIBUTION.http;
|
|
const contracts = composeContractContributions([
|
|
Object.freeze({
|
|
...TEST_CONTRACT_CONTRIBUTION,
|
|
http: Object.freeze([
|
|
{
|
|
...listRow!,
|
|
contract: {
|
|
...listRow!.contract,
|
|
outputValidator: unvalidatedPayload(
|
|
"TestEntityListPayload",
|
|
"typed by the package",
|
|
),
|
|
},
|
|
},
|
|
...rest,
|
|
]),
|
|
}),
|
|
]);
|
|
render(
|
|
<ApplicationProvider application={createTestApplication()}>
|
|
<LocaleProvider>
|
|
<PlatformOverviewPage contracts={contracts} />
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
);
|
|
|
|
const table = tableByCaption("런타임 검증을 생략한 계약");
|
|
const [row, ...others] = within(table).getAllByRole("row").slice(1);
|
|
expect(others).toHaveLength(0);
|
|
expect(within(row!).getByText("TEST_LIST_ENTITIES")).toBeVisible();
|
|
expect(within(row!).getByText("typed by the package")).toBeVisible();
|
|
});
|
|
|
|
it("shows no skipped-validation list when every operation validates", () => {
|
|
renderPage();
|
|
|
|
expect(
|
|
screen.queryByRole("table", { name: "런타임 검증을 생략한 계약" }),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("renders every fixed server-state profile with its own budget", () => {
|
|
renderPage();
|
|
|
|
const table = tableByCaption("서버 상태 프로파일");
|
|
for (const profile of Object.values(SERVER_STATE_PROFILES)) {
|
|
expect(within(table).getByText(profile.profileId)).toBeInTheDocument();
|
|
}
|
|
expect(within(table).getAllByRole("row").slice(1)).toHaveLength(
|
|
Object.keys(SERVER_STATE_PROFILES).length,
|
|
);
|
|
});
|
|
|
|
it("labels a capability that was never selected as unselected", () => {
|
|
renderPage();
|
|
|
|
const region = screen.getByRole("region", { name: "선택적 런타임 능력" });
|
|
|
|
expect(within(region).getAllByText("미선택")).toHaveLength(4);
|
|
expect(within(region).queryByText("운영자가 비활성화함")).toBeNull();
|
|
});
|
|
|
|
it("separates an operator disable from a capability that was never selected", () => {
|
|
render(
|
|
<ApplicationProvider
|
|
application={createTestApplication({
|
|
runtimeCapabilities: createRuntimeCapabilitiesStub({
|
|
SERVICE_WORKER: { selected: 1, active: 0, override: "DISABLED" },
|
|
OFFLINE_COMMANDS: { selected: 1, active: 1 },
|
|
}),
|
|
})}
|
|
>
|
|
<LocaleProvider>
|
|
<PlatformOverviewPage contracts={COMPOSED_CONTRACT_CONTRIBUTIONS} />
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
);
|
|
|
|
const region = screen.getByRole("region", { name: "선택적 런타임 능력" });
|
|
|
|
expect(within(region).getByText("운영자가 비활성화함")).toBeVisible();
|
|
expect(within(region).getByText("활성 (1)")).toBeVisible();
|
|
expect(within(region).getAllByText("미선택")).toHaveLength(2);
|
|
});
|
|
|
|
it("counts installed contract packages separately from template fixtures", () => {
|
|
const fixtures = COMPOSED_CONTRACT_CONTRIBUTIONS.contributions.filter(
|
|
(contribution) => contribution.source.kind === "TEMPLATE_FIXTURE",
|
|
).length;
|
|
renderPage();
|
|
|
|
const summary = screen.getByRole("region", { name: "설치 요약" });
|
|
const packages = metricByLabel(summary, "외부 계약 패키지");
|
|
|
|
expect(
|
|
within(packages).getByText(
|
|
`${COMPOSED_CONTRACT_CONTRIBUTIONS.externalPackages.length}개`,
|
|
),
|
|
).toBeVisible();
|
|
expect(
|
|
within(packages).getByText(`템플릿 픽스처 ${fixtures}개`),
|
|
).toBeVisible();
|
|
expect(
|
|
within(metricByLabel(summary, "라우트")).getByText(
|
|
`${Object.keys(ROUTE_REGISTRY).length}개`,
|
|
),
|
|
).toBeVisible();
|
|
});
|
|
|
|
it("renders the verified release identity once the runtime resolves it", async () => {
|
|
renderPage();
|
|
|
|
const region = screen.getByRole("region", { name: "릴리스 신원" });
|
|
await waitFor(() =>
|
|
expect(
|
|
within(metricByLabel(region, "빌드")).getByText("test-build"),
|
|
).toBeVisible(),
|
|
);
|
|
expect(
|
|
within(metricByLabel(region, "릴리스")).getByText("test-release"),
|
|
).toBeVisible();
|
|
});
|
|
|
|
it("stops the release metrics from loading forever", async () => {
|
|
render(
|
|
<ApplicationProvider
|
|
application={createTestApplication({
|
|
releaseInfo: {
|
|
getCurrent: async () => {
|
|
throw new Error("manifest unavailable");
|
|
},
|
|
refresh: async () => {
|
|
throw new Error("manifest unavailable");
|
|
},
|
|
},
|
|
})}
|
|
>
|
|
<LocaleProvider>
|
|
<PlatformOverviewPage contracts={COMPOSED_CONTRACT_CONTRIBUTIONS} />
|
|
</LocaleProvider>
|
|
</ApplicationProvider>,
|
|
);
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByText("런타임 정보를 확인하지 못했습니다."),
|
|
).toBeVisible(),
|
|
);
|
|
expect(
|
|
screen.queryByText("런타임 정보를 확인하고 있습니다."),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
});
|