Files
clean-architecture-frontend…/tests/unit/product-runtime-capability-selection.test.ts
DongHyeonka 2963c6f42c fix(features): 선택 런타임(SW 등) 선택을 제품 소유 파일로 옮긴다 (1103/09-05)
문제
Service Worker를 켜는 유일한 방법은 src/features/installed-runtime-capabilities.ts의
SERVICE_WORKER 상수를 바꾸는 것이었다. 그 파일에는 "Product-owned." 표시가
없고, 매뉴얼 03 D절은 src/features/installed-*.ts를 고치지 말라고 한다.
매뉴얼대로 하면 SW를 켤 수 없고, 켜면 동기화마다 템플릿 파일을 손으로
병합한다. 템플릿 상태 설명과 제품 선택 상수가 한 블록에 섞여 있었다(1101/09-05).

고른 방법
리뷰의 최소 방향을 따른다.
- 선택 상수 넷(REALTIME, WEB_WORKERS, SERVICE_WORKER, OFFLINE_COMMANDS)을 제품
  소유 src/features/product-capabilities.ts의
  PRODUCT_RUNTIME_CAPABILITY_SELECTION으로 옮긴다. 09-02에서 만든 같은 새 제품
  소유 파일이다. product-contracts.ts에 넣지 않은 이유: 계약 층(src/contracts)이
  아니라 기능 카탈로그 옆의 선택이고, 템플릿은 복사 뒤 기존 제품 소유 파일에
  칸을 더하지 않는다.
- installed-runtime-capabilities.ts는 템플릿 소유로 남고 그 선택을 검사
  (validateRealtimeContributions, validateWebWorkerContributions)하고 투영만
  한다. §3.5 설명과 템플릿 상태 설명은 여기에 남는다.
- 매뉴얼 03 C절에 "SW 켜기"를 넣었다. 조립 거절 메시지, e2e SW 빌드 도우미의
  편집 대상(premise 1), 레시피·운영 문서, dependency-cruiser 주석의 경로를
  새 파일로 바꿨다.
- 09-02 typecheck 테스트는 이제 출하된 product-capabilities.ts에 타입만 채우고
  (선택은 유지), 복사 목록은 REMOVAL_FIXTURE_COPY_TARGETS 하나를 쓴다.

위험·한계
- 리뷰가 함께 제안한 composeProduct의 SW 연결 칸(blockers, observe)은 만들지
  않았다. 그 연결은 여전히 템플릿 파일 create-runtime-composition.ts를 고쳐야
  한다. 매뉴얼 "SW 켜기"에 적었다.
- 템플릿 안의 선택을 이미 바꾼 다운스트림은 값을 새 파일로 옮겨야 한다.

검증
- RED: tests/unit/product-runtime-capability-selection.test.ts 3건(선택이 제품
  소유 파일에만 있음, 제품 SW 선택 투영, 잘못된 선택은 여전히 검사)이 수정 전
  실패.
- 그 테스트, service-worker-build-output, optional-runtime-host,
  runtime-composition-service-worker-telemetry, product-features,
  product-extension-typecheck, runtime-adapters 통과.
- check:types, check:architecture, eslint, verify:documentation PASS_SCOPED.

Refs: docs/reviews/2026-11-03-maturity-review/09-app-core.md 09-05
2026-11-04 20:35:11 +09:00

68 lines
2.4 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { afterEach, describe, expect, it, vi } from "vitest";
/**
* 1103/09-05. The static optional-capability selection (§3.5) is the
* product's choice, so it lives in a product-owned file. Turning the Service
* Worker on is an edit there; `installed-runtime-capabilities.ts` stays the
* template's and only validates and projects what the product selected.
*/
const source = (file: string) =>
readFile(new URL(`../../${file}`, import.meta.url), "utf8");
const ACTIVE = Object.freeze({
mode: "ACTIVE" as const,
scriptPath: "service-worker.js" as const,
handlers: Object.freeze(["PWA_STATIC_ASSETS" as const]),
});
afterEach(() => {
vi.doUnmock("../../src/features/product-capabilities.ts");
vi.resetModules();
});
async function installedWith(selection: Record<string, unknown>) {
vi.resetModules();
vi.doMock("../../src/features/product-capabilities.ts", () => ({
PRODUCT_RUNTIME_CAPABILITY_SELECTION: Object.freeze({
realtime: Object.freeze([]),
webWorkers: Object.freeze([]),
serviceWorker: null,
offlineCommands: null,
...selection,
}),
}));
return (await import("../../src/features/installed-runtime-capabilities.ts"))
.INSTALLED_RUNTIME_CAPABILITIES;
}
describe("1103/09-05 the optional runtime selection is product-owned", () => {
it("declares the selection in the product-owned file only", async () => {
const product = await source("src/features/product-capabilities.ts");
const installed = await source("src/features/installed-runtime-capabilities.ts");
expect(product).toContain("Product-owned.");
// tests/e2e/support/service-worker-builds.ts premise 1 edits this line.
expect(
product.match(/const SERVICE_WORKER: InstalledServiceWorkerSelection \| null = /gu),
).toHaveLength(1);
expect(installed).not.toContain("Product-owned.");
expect(installed).not.toMatch(/const (REALTIME|WEB_WORKERS|SERVICE_WORKER|OFFLINE_COMMANDS)\b/u);
});
it("projects the product's Service Worker selection", async () => {
const installed = await installedWith({ serviceWorker: ACTIVE });
expect(installed.serviceWorker).toEqual(ACTIVE);
expect(Object.isFrozen(installed)).toBe(true);
});
it("still validates what the product selected", async () => {
await expect(
installedWith({ webWorkers: Object.freeze([Object.freeze({ taskGroupId: "" })]) }),
).rejects.toThrow(TypeError);
});
});