정리 4단계의 R2 검사는 등록부를 쓰는 7곳만 봤다. 그 밖에 루트 이름을 담은 목록이 코드 15파일에 19개 따로 있어, 루트 항목 하나를 옮기면 여전히 여러 곳을 같이 고쳐야 했다. - 등록부에 집합 12개를 더했다. 사본 복사에서 건너뛰는 항목 셋 (checkout·provider·공급망 fixture), fixture 코드 범위, pnpm 매니페스트, Playwright 설정, visual 증거, 문서 입력, 에이전트 하네스, tsconfig 묶음 셋. 각 집합 설명에 읽는 파일을 적었다. - 사본이 건너뛰는 node_modules·dist·.tmp 같은 추적 안 하는 항목은 종류 untracked(optional)로 적는다. 추적 파일이 있으면 시험이 실패한다. - 19개 목록이 모두 집합을 고른다. 집합의 원소는 전과 같아 동작은 바뀌지 않는다. - R2 시험이 추적되는 코드 파일 전체를 본다. 루트 항목(이나 그 안 경로)만 담은 문자열 배열에 추적되는 루트 이름이 둘 이상이면 실패. 인자 목록은 `--` 뒤만 본다. main의 옛 목록 18개를 이 검사가 잡는 것을 확인했다. - 집합마다 selectRepositoryPaths·selectRepositoryEntries로 고르는 코드가 있는지 본다. 문서를 복사하지 않는 제거 drill(FE-GATE-020)은 문서 시험(REMOVAL_FIXTURE_DOCUMENT_TESTS)을 지우는데, 집합 셋 (agent-harness·documentation-inputs·feature-typecheck)은 그 시험만 읽는다. 시험이 이 셋을 적어 두고, 문서 시험이 지워진 사본에서만 셋이 비는 것을 허용한다. 셋이 바뀌면 전체 checkout에서 실패한다. - 파서가 kinds·sets 설명과 코드의 목록이 같은지 본다. - .gitignore 주석이 a11y 기록을 아직 artifacts/ 아래라고 적던 것을 고쳤다(정리 3단계에서 docs/로 옮김). 검증(desktop): test:unit, check:types, check:ci, lint, verify:documentation. repository-layout 시험을 문서 없는 제거 사본과 feature-scaffold 사본에서도 돌렸고, 집합 하나의 읽는 곳을 지우면 두 곳 모두 실패한다.
191 lines
6.6 KiB
TypeScript
191 lines
6.6 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterAll, describe, expect, it } from "vitest";
|
|
|
|
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
|
import { selectRepositoryPaths } from "../../scripts/lib/repository-layout.ts";
|
|
|
|
/**
|
|
* 09-01. The central composers (`src/features/installed-*`) are typed from the
|
|
* generated feature index, so the repository's own typecheck only ever sees
|
|
* the features it ships. This installs two more into a copy of `src`, in a
|
|
* context of their own so the check survives the sample's removal: one with a
|
|
* route, route codecs and both locales but no adapter, and one shaped
|
|
* differently on every composed axis (an adapter that needs telemetry, no
|
|
* routes, no codecs, one locale). Each declares its executable half in a
|
|
* separate \`feature-runtime.ts\` loaded through \`loadRuntime\` (15-01). It
|
|
* regenerates the index with the production generator and runs the app
|
|
* typecheck over the copy.
|
|
*/
|
|
const SECOND_FEATURE_MODULE = `import { defineFeatureModule } from "../feature-module.ts";
|
|
|
|
export const FEATURE_MODULE_ID = "second-feature";
|
|
export const FEATURE_CONTEXT_ID = "two-feature-context";
|
|
|
|
export const FEATURE_MODULE = defineFeatureModule({
|
|
id: FEATURE_MODULE_ID,
|
|
contracts: {
|
|
featureId: FEATURE_MODULE_ID,
|
|
routes: {},
|
|
routeRuntimeContracts: {},
|
|
// Frozen empty arrays type as \`readonly never[]\`, not \`readonly []\`.
|
|
invalidation: {
|
|
topics: Object.freeze([]),
|
|
namespaces: Object.freeze([]),
|
|
edges: Object.freeze([]),
|
|
},
|
|
topicVersions: Object.freeze([]),
|
|
contractPackages: Object.freeze([]),
|
|
},
|
|
routes: {},
|
|
messages: { "en-US": { "secondFeature.title": "Second feature" } },
|
|
loadRuntime: async () => (await import("./feature-runtime.ts")).FEATURE_RUNTIME,
|
|
} as const);
|
|
`;
|
|
|
|
const SECOND_FEATURE_RUNTIME = `import { defineFeatureAdapterContribution } from "../feature-adapter-contribution.ts";
|
|
import { defineFeatureRuntime } from "../feature-module.ts";
|
|
|
|
type SecondFeatureInput = Readonly<{ ping(): string }>;
|
|
|
|
declare module "../../application/ports/in/application-api.ts" {
|
|
interface ApplicationFeatureInputs {
|
|
"second-feature": SecondFeatureInput;
|
|
}
|
|
}
|
|
|
|
export const FEATURE_RUNTIME = defineFeatureRuntime({
|
|
featureId: "second-feature",
|
|
schemas: {},
|
|
adapters: [
|
|
defineFeatureAdapterContribution({
|
|
featureId: "second-feature",
|
|
needs: ["telemetry"] as const,
|
|
createInput: () =>
|
|
Object.freeze({
|
|
featureId: "second-feature",
|
|
input: Object.freeze({ ping: () => "pong" }),
|
|
}),
|
|
}),
|
|
],
|
|
contractContributions: [],
|
|
} as const);
|
|
`;
|
|
|
|
const SECOND_FEATURE_ROUTES = `import type { RouteObject } from "react-router-dom";
|
|
|
|
export const FEATURE_CONTEXT_ROUTES: readonly RouteObject[] = Object.freeze([]);
|
|
`;
|
|
|
|
const ROUTED_FEATURE_MODULE = `import { defineFeatureModule } from "../feature-module.ts";
|
|
|
|
export const FEATURE_MODULE_ID = "routed-feature";
|
|
export const FEATURE_CONTEXT_ID = "two-feature-context";
|
|
|
|
const ROUTES = {
|
|
ROUTED_ITEMS: {
|
|
routeId: "ROUTED_ITEMS",
|
|
path: "/two-feature/items",
|
|
paramsSchema: null,
|
|
searchSchema: null,
|
|
access: "public",
|
|
loadingSurface: "routed-items",
|
|
errorSurface: "feature-boundary",
|
|
chunkId: "route-routed-items",
|
|
title: "route.ROUTED_ITEMS.title",
|
|
navigationLabel: null,
|
|
navigationOrder: null,
|
|
},
|
|
} as const;
|
|
|
|
const MESSAGES = {
|
|
"route.ROUTED_ITEMS.title": "Routed items",
|
|
"route.ROUTED_ITEMS.navigation": "Routed items",
|
|
} as const;
|
|
|
|
export const FEATURE_MODULE = defineFeatureModule({
|
|
id: FEATURE_MODULE_ID,
|
|
contracts: {
|
|
featureId: FEATURE_MODULE_ID,
|
|
routes: ROUTES,
|
|
routeRuntimeContracts: {
|
|
ROUTED_ITEMS: {
|
|
routeId: "ROUTED_ITEMS",
|
|
moduleId: "routed-items-page",
|
|
paramsCodec: "none",
|
|
searchCodec: "none",
|
|
},
|
|
},
|
|
invalidation: { topics: [], namespaces: [], edges: [] },
|
|
topicVersions: [],
|
|
contractPackages: [],
|
|
},
|
|
routes: ROUTES,
|
|
messages: { "ko-KR": MESSAGES, "en-US": MESSAGES },
|
|
loadRuntime: async () => ({
|
|
featureId: FEATURE_MODULE_ID,
|
|
schemas: {},
|
|
adapters: [],
|
|
contractContributions: [],
|
|
}),
|
|
} as const);
|
|
`;
|
|
|
|
const CONTEXT_MODULE = `export const CONTEXT_MODULE_ID = "two-feature-context";
|
|
export const CONTEXT_APP_ID = "template-app";
|
|
export const CONTEXT_ROUTE_PATH = "two-feature/*";
|
|
export const CONTEXT_MAX_FEATURES = 2;
|
|
`;
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterAll(async () => {
|
|
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("installing a second feature (09-01)", () => {
|
|
it("keeps the app typecheck green with two differently shaped features", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "two-feature-install-"));
|
|
roots.push(root);
|
|
await cp(path.resolve("src"), path.join(root, "src"), { recursive: true });
|
|
for (const config of selectRepositoryPaths("app-typecheck")) {
|
|
await cp(path.resolve(config), path.join(root, config));
|
|
}
|
|
await linkFixtureNodeModules(root);
|
|
const files: Readonly<Record<string, string>> = {
|
|
"src/contexts/two-feature-context/context-module.ts": CONTEXT_MODULE,
|
|
"src/features/routed-feature/feature-module.ts": ROUTED_FEATURE_MODULE,
|
|
"src/features/routed-feature/context-routes.ts": SECOND_FEATURE_ROUTES,
|
|
"src/features/second-feature/feature-module.ts": SECOND_FEATURE_MODULE,
|
|
"src/features/second-feature/feature-runtime.ts": SECOND_FEATURE_RUNTIME,
|
|
"src/features/second-feature/context-routes.ts": SECOND_FEATURE_ROUTES,
|
|
};
|
|
for (const [file, content] of Object.entries(files)) {
|
|
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
|
|
await writeFile(path.join(root, file), content);
|
|
}
|
|
|
|
const generated = spawnSync(
|
|
process.execPath,
|
|
[path.resolve("scripts/generate-product-feature-index.ts"), `--root=${root}`],
|
|
{ encoding: "utf8" },
|
|
);
|
|
expect(generated.stderr).toBe("");
|
|
expect(generated.status).toBe(0);
|
|
const index = await readFile(path.join(root, "src/.generated/product-feature-index.ts"), "utf8");
|
|
expect(index).toContain("../features/second-feature/feature-module.ts");
|
|
expect(index).toContain("../features/routed-feature/feature-module.ts");
|
|
|
|
const typecheck = spawnSync(
|
|
path.resolve("node_modules/.bin/tsc"),
|
|
["--project", path.join(root, "tsconfig.app.json")],
|
|
{ encoding: "utf8" },
|
|
);
|
|
expect(typecheck.stdout + typecheck.stderr).toBe("");
|
|
expect(typecheck.status).toBe(0);
|
|
}, 60_000);
|
|
});
|