문제
lab 게이트 FE-GATE-026은 내비게이션 클릭부터 플랫폼 구성 화면 제목이
보일 때까지를 잰다. 298201f 뒤로 이 route module은 그리기 전에
loadInstalledFeatureRuntimeRegistries()를 기다린다. 그 함수는 설치된
모든 기능의 실행부를 dynamic import한다. 그래서 클릭 뒤 요청 묶음이
두 번이 되고 상호작용 중앙값이 117 -> 227 ms가 됐다(예산 200 ms).
고른 방법 (영역 문서 최소 개선 방향 (c))
- route module은 페이지 컴포넌트를 바로 돌려준다(default export).
제목·릴리스·라우트 표·서버 상태·능력·기능 상태처럼 선언과 런타임
snapshot으로 아는 것은 바로 그린다.
- 실행부가 있어야 아는 것(HTTP 오퍼레이션 수, 픽스처 수, 오퍼레이션
표, 검증 생략 표)만 Suspense 경계 두 곳 뒤에서 use()로 채운다.
- 실행부 조립 모듈도 dynamic import로 바꿔 제목이 기다리는 페이지
청크에서 뺐다(첫 요청 묶음 8,095 -> 6,919 B).
- 기능 사이 중복은 여전히 이 화면에서 throw하고 route 경계로 간다.
실패한 load는 캐시에서 지워 다음 방문 때 다시 시도한다.
- 버린 대안: 예산 300 ms(회귀를 숨김), lab 대상 라우트 변경(같은
이유), hover 프리페치(키보드·직접 진입에 효과 작음).
위험·한계
- 화면 안에 "기능 실행부를 불러오고 있습니다." 로딩 상태가 생긴다.
- PlatformOverviewPage의 contracts prop이 Promise가 됐다. 이 컴포넌트를
직접 쓰는 다운스트림 테스트는 Promise를 넘기고 act로 기다려야 한다.
- 첫 요청 묶음은 d99301b보다 여전히 크다(6,919 vs 5,019 B). 그 사이
페이지가 커졌고 badge·card가 공유 청크로 갈라졌다. 그래서 d99301b보다
약 30 ms 느리다.
- 실제 CI 러너에서는 재지 않았다.
검증
- 새 component 테스트(실행부 load가 끝나지 않아도 제목·라우트 표가
보이고 오퍼레이션 표만 로딩): 수정 전 실패, 수정 뒤 통과.
- test:component 통과. check:types, check:architecture, 바뀐 파일
eslint 통과.
- lab A/B(heavy lock, 같은 호스트, d99301b worktree와 번갈아,
test:performance --runs=5, CHOKIDAR_USEPOLLING=1, 이 브랜치 끝 기준):
부하 19 -> 11에서 d99301b 107·106 ms PASS, 이 변경 136·134 ms PASS.
LCP 1,968·1,984 ms, CLS 0. (같은 날 다른 묶음 한 번은 두 쪽 모두
홈 링크를 30초 안에 찾지 못해 측정 전에 끝났다. 포트를 바꿔 다시
잰 것이 위 결과다.)
- 요청 추적: 클릭 뒤 제목은 첫 묶음(페이지 청크 4개) 뒤에 나오고,
feature-runtime·reference-schemas는 제목 뒤에 받는다.
Refs: docs/reviews/2026-11-03-maturity-review/15-performance.md 15-01
246 lines
8.5 KiB
TypeScript
246 lines
8.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act, render, screen, waitFor, within } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
composeContractContributions,
|
|
type ComposedContractContributions,
|
|
} 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.
|
|
*/
|
|
|
|
/**
|
|
* 1103/15-01. The contract tables wait for the features' runtime halves
|
|
* behind their own Suspense boundary; `act` lets the given promise settle.
|
|
*/
|
|
async function renderPage(
|
|
options: Readonly<{
|
|
application?: ReturnType<typeof createTestApplication>;
|
|
contracts?: ComposedContractContributions;
|
|
}> = {},
|
|
) {
|
|
await act(async () => {
|
|
render(
|
|
<ApplicationProvider
|
|
application={options.application ?? createTestApplication()}
|
|
>
|
|
<LocaleProvider>
|
|
<PlatformOverviewPage
|
|
contracts={Promise.resolve(
|
|
options.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", async () => {
|
|
await 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", async () => {
|
|
const operationIds = [
|
|
...COMPOSED_CONTRACT_CONTRIBUTIONS.httpByOperationId.keys(),
|
|
];
|
|
await 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", async () => {
|
|
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,
|
|
]),
|
|
}),
|
|
]);
|
|
await renderPage({ contracts });
|
|
|
|
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", async () => {
|
|
await renderPage();
|
|
|
|
expect(
|
|
screen.queryByRole("table", { name: "런타임 검증을 생략한 계약" }),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("renders every fixed server-state profile with its own budget", async () => {
|
|
await 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", async () => {
|
|
await 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", async () => {
|
|
await renderPage({
|
|
application: createTestApplication({
|
|
runtimeCapabilities: createRuntimeCapabilitiesStub({
|
|
SERVICE_WORKER: { selected: 1, active: 0, override: "DISABLED" },
|
|
OFFLINE_COMMANDS: { selected: 1, active: 1 },
|
|
}),
|
|
}),
|
|
});
|
|
|
|
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", async () => {
|
|
const fixtures = COMPOSED_CONTRACT_CONTRIBUTIONS.contributions.filter(
|
|
(contribution) => contribution.source.kind === "TEMPLATE_FIXTURE",
|
|
).length;
|
|
await 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 () => {
|
|
await 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 () => {
|
|
await renderPage({
|
|
application: createTestApplication({
|
|
releaseInfo: {
|
|
getCurrent: async () => {
|
|
throw new Error("manifest unavailable");
|
|
},
|
|
refresh: async () => {
|
|
throw new Error("manifest unavailable");
|
|
},
|
|
},
|
|
}),
|
|
});
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByText("런타임 정보를 확인하지 못했습니다."),
|
|
).toBeVisible(),
|
|
);
|
|
expect(
|
|
screen.queryByText("런타임 정보를 확인하고 있습니다."),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
});
|