문제 첫 글꼴 규칙(check:design-system)은 --font-sans의 첫 글꼴이 일반 키워드이거나 검사하는 CSS 안의 @font-face로 실릴 때만 통과시킨다. 글꼴 패키지 import, @import url(…), index.html의 <link>로 싣는 글꼴은 볼 수 없어 실패한다. memento 토큰이 이미 이 규칙에 걸린다. 선언할 곳이 없으니 제품은 템플릿 소유 스크립트를 고치게 된다. 고른 방법 - token-contract.ts에 PRODUCT_LOADED_FONT_FAMILIES(템플릿은 빈 목록)를 둔다. 제품은 토큰 계약 파일에서 자기가 싣는 글꼴 이름을 적는다. - firstFontFamilyFailures가 세 번째 인자로 이 목록을 받아 @font-face로 실은 글꼴과 같이 허용한다. check-design-system.ts가 목록을 넘긴다. - 실패 메시지에 목록 이름을 넣어 어디에 선언하는지 알린다. - docs/styling/design-system-platform.md 4.1절 표의 첫 글꼴 행을 고친다. - 12-04의 (1)~(3)과 (5)는 e714c0d가 했다(deg·음수 색상각, 지원 형식을 적는 포커스 메시지, -apple-system·BlinkMacSystemFont, 규칙 문서). 이 커밋은 (4)만 한다. 버린 대안 - 패키지 import·<link>를 찾아 실제로 싣는지 판정: 진입점·CDN·번들러 설정까지 봐야 해서 규칙이 커진다. - 목록을 design-system/index.ts로도 내보내기: 앱 코드가 쓰지 않는다. 위험·한계 - 검사는 목록을 믿는다. 글꼴이 실제로 실리는지 보지 않는다. 주석과 문서에 "모든 화면이 싣는 글꼴만 적는다"고 적었다. - 실패 메시지 문구가 바뀐다. 문구를 단언하는 곳은 tests/unit/design-system-rules.test.ts뿐이다. - 새 공개 이름 PRODUCT_LOADED_FONT_FAMILIES가 생긴다. 검증 - RED: 새 테스트 "passes a family the product declares it loads, and only that one"이 실패(expected [ Array(1) ] to deeply equal []). - GREEN: design-system-rules·oklch-contrast·design-system-contract 22/22 통과. - 실제 스크립트 probe: CSS 사본의 --font-sans를 "Pretendard Variable"로 시작하게 하고 node scripts/check-design-system.ts → 빈 목록이면 새 메시지로 실패(exit 1), 목록에 넣으면 PASS(exit 0). 저장소 CSS는 PASS. - tsc(app·node·test), 바꾼 파일 eslint, verify-documentation-readiness PASS_SCOPED. Refs: docs/reviews/2026-11-01-maturity-review/12-guardrails-ci.md 12-04
184 lines
6.0 KiB
TypeScript
184 lines
6.0 KiB
TypeScript
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
|
import { designSystemReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
REQUIRED_PRIMITIVE_TOKENS,
|
|
REQUIRED_SEMANTIC_TOKENS,
|
|
} from "../src/presentation/design-system/tokens/token-contract.ts";
|
|
import {
|
|
firstFontFamilyFailures,
|
|
focusContrastFailures,
|
|
hueMixFailures,
|
|
unreadTokenFailures,
|
|
} from "./lib/design-system-rules.ts";
|
|
import { readCustomProperties } from "./lib/oklch-contrast.ts";
|
|
|
|
const fixtureMode = process.argv.includes("--fixture");
|
|
const failures: string[] = [];
|
|
const tokenFiles = {
|
|
primitive: "src/presentation/design-system/tokens/primitive.css",
|
|
semantic: "src/presentation/design-system/tokens/semantic.css",
|
|
component: "src/presentation/design-system/tokens/component.css",
|
|
};
|
|
const tokenLayers: Array<readonly [string, string, readonly string[]]> = [
|
|
["primitive", tokenFiles.primitive, REQUIRED_PRIMITIVE_TOKENS],
|
|
["semantic", tokenFiles.semantic, REQUIRED_SEMANTIC_TOKENS],
|
|
["component", tokenFiles.component, REQUIRED_COMPONENT_TOKENS],
|
|
];
|
|
|
|
for (const [layer, file, tokens] of tokenLayers) {
|
|
const source = await readFile(file, "utf8");
|
|
for (const token of tokens) {
|
|
if (!source.includes(`${token}:`)) {
|
|
failures.push(`${layer} token is missing: ${token}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// theme.css only imports the files under styles/theme/, so check them all.
|
|
const styleFiles = (
|
|
await readdir("src/presentation/styles", { recursive: true })
|
|
)
|
|
.filter((file) => file.endsWith(".css"))
|
|
.map((file) => path.join("src/presentation/styles", file));
|
|
const cssSources = await Promise.all(
|
|
[...Object.values(tokenFiles), ...styleFiles].map(
|
|
async (file) => ({ file, source: await readFile(file, "utf8") }),
|
|
),
|
|
);
|
|
const definitions = new Set(
|
|
cssSources.flatMap(({ source }) =>
|
|
[...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1]),
|
|
),
|
|
);
|
|
for (const { file, source } of cssSources) {
|
|
for (const match of source.matchAll(/var\((--[a-z0-9-]+)/g)) {
|
|
if (!definitions.has(match[1])) {
|
|
failures.push(`${file} uses undefined token ${match[1]}`);
|
|
}
|
|
}
|
|
failures.push(...hueMixFailures({ file, source }));
|
|
}
|
|
|
|
const semanticSource = await readFile(tokenFiles.semantic, "utf8");
|
|
const darkSource =
|
|
semanticSource.match(/:root\[data-theme="dark"\]\s*\{([\s\S]*?)\n\}/)?.[1] ??
|
|
"";
|
|
for (const token of [
|
|
"--color-surface",
|
|
"--color-surface-muted",
|
|
"--color-surface-elevated",
|
|
"--color-content",
|
|
"--color-content-muted",
|
|
"--color-content-inverse",
|
|
"--color-border",
|
|
"--color-border-strong",
|
|
"--color-action",
|
|
"--color-action-hover",
|
|
"--color-action-pressed",
|
|
"--color-danger",
|
|
"--color-focus",
|
|
"--color-disabled-content",
|
|
"--color-disabled-surface",
|
|
]) {
|
|
if (!darkSource.includes(`${token}:`)) {
|
|
failures.push(`dark theme token is missing: ${token}`);
|
|
}
|
|
}
|
|
const lightProperties = new Map([
|
|
...readCustomProperties(await readFile(tokenFiles.primitive, "utf8")),
|
|
...readCustomProperties(semanticSource.split(':root[data-theme="dark"]')[0]),
|
|
]);
|
|
const darkProperties = new Map([
|
|
...lightProperties,
|
|
...readCustomProperties(darkSource),
|
|
]);
|
|
// Rule texts and reasons: scripts/lib/design-system-rules.ts.
|
|
failures.push(
|
|
...focusContrastFailures("light", lightProperties),
|
|
...focusContrastFailures("dark", darkProperties),
|
|
...unreadTokenFailures(
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
cssSources.filter(({ file }) => file !== tokenFiles.component),
|
|
),
|
|
...firstFontFamilyFailures(
|
|
lightProperties.get("--font-sans") ?? "",
|
|
cssSources,
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
),
|
|
);
|
|
|
|
const componentSource = await readFile(tokenFiles.component, "utf8");
|
|
if (!componentSource.includes("@media (forced-colors: active)")) {
|
|
failures.push("forced-colors token fallback is missing");
|
|
}
|
|
|
|
async function listSourceFiles(directory: string): Promise<string[]> {
|
|
const result: string[] = [];
|
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
const target = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) result.push(...(await listSourceFiles(target)));
|
|
else if (/\.(?:ts|tsx|mts|cts)$/.test(entry.name)) result.push(target);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const sources = fixtureMode
|
|
? await listSourceFiles("tests/fixtures/design-system/forbidden")
|
|
: await listSourceFiles("src");
|
|
for (const file of sources) {
|
|
const source = await readFile(file, "utf8");
|
|
// Icon vendor and design-system deep imports are graph rules in
|
|
// .dependency-cruiser.json (check:architecture), which also sees relative,
|
|
// dynamic and type imports (12-08, 12-10).
|
|
if (
|
|
/from\s+["'](?:react-aria-components|@radix-ui\/[^"']+)["']/.test(source)
|
|
) {
|
|
failures.push(`direct headless vendor import in ${file}`);
|
|
}
|
|
if (
|
|
!file.includes("src/presentation/design-system/tokens/") &&
|
|
/(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i.test(source)
|
|
) {
|
|
failures.push(`raw palette value in ${file}`);
|
|
}
|
|
if (
|
|
file.includes("tests/fixtures/design-system/forbidden") &&
|
|
source.includes("TOOLTIP_ONLY_REQUIRED_INFORMATION")
|
|
) {
|
|
failures.push(`tooltip-only required information in ${file}`);
|
|
}
|
|
}
|
|
|
|
const report = designSystemReportArtifactSchema.parse({
|
|
schemaVersion: 1,
|
|
mode: fixtureMode ? "negative-fixture" : "source",
|
|
checkedTokenCount:
|
|
REQUIRED_PRIMITIVE_TOKENS.length +
|
|
REQUIRED_SEMANTIC_TOKENS.length +
|
|
REQUIRED_COMPONENT_TOKENS.length,
|
|
failures,
|
|
passed: failures.length === 0,
|
|
});
|
|
await mkdir("artifacts/quality", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: fixtureMode
|
|
? "artifacts/quality/design-system-fixture.json"
|
|
: "artifacts/quality/design-system.json",
|
|
schema: designSystemReportArtifactSchema,
|
|
value: report,
|
|
});
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(`Design system contract failed:\n${failures.join("\n")}\n`);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Design system contract: ${report.checkedTokenCount} tokens and headless vendor boundary PASS\n`,
|
|
);
|