FE-GATE-029는 check:design-system:fixture와 check:diagnostics:fixture가 exit 1과 머리말을 내면 통과로 센다. 거절된 파일이 하나만 있어도 그 조건이 채워진다. 그래서 검사기에서 진짜 규칙(TSX의 raw palette·hue mix·inline style, direct console·민감 context)을 지워도 029가 초록이었다. fixture 폴더에서만 도는 표식 규칙(TOOLTIP_ONLY_REQUIRED_INFORMATION, UNKNOWN_DIAGNOSTIC_EVENT)이 자기 파일을 늘 거절했기 때문이다. check-i18n.ts가 하던 파일별 판정을 scripts/lib/fixture-rejection.ts로 옮기고 세 검사기가 같이 쓴다. fixture 모드에서 어느 failure도 이름을 대지 않는 fixture 파일이 있거나 fixture 파일이 하나도 없으면, 그 목록을 찍고 exit 2로 끝난다. 029는 exit 1을 기대하므로 실패한다. 파일 이름은 경로 경계로 맞춘다(a.ts가 a.tsx·b/a.ts에 맞지 않는다). i18n 판정은 endsWith에서 이 판정으로 바뀌어 조금 엄격해진다. 표식 규칙 둘을 지운다. tooltip-only.tsx는 그 표식 말고 거절할 규칙이 없어 지운다. headless-vendor-import.tsx·hue-mix.tsx를 더하고, raw-palette.tsx는 inline style 없이 SVG fill로 바꿔 fixture 하나가 규칙 하나에 걸리게 한다. direct-console.ts에서는 표식 문자열을 뺀다. fe-design-system 스킬이 지운 tooltip 규칙을 있는 것처럼 적던 줄도 고친다. 버린 안: gates.json의 expectedDiagnosticId를 규칙 문구로 좁히기. 항목 범위가 029 정의를 바꾸지 말라고 하고, 규칙이 여럿이라 문구 하나로는 다 못 본다. 한계: 파일마다 「failure가 하나라도 있는지」를 본다. fixture 하나에 서로 다른 규칙 둘이 걸리면 하나를 지워도 다른 하나가 거절한다. 지금 fixture는 규칙 하나씩이고 시험이 failure 목록을 그대로 단언하지만, 새 fixture에 그것을 강제하지는 않는다. check-i18n.ts가 helper를 부르는지 단언하는 시험은 없다(main에도 없다). 시험: design-system-rules.test.ts·fixture-rejection.test.ts가 임시 root에서 검사기를 돌려, fixture마다 기대한 failure만 나오는지와 거절되지 않는 파일을 더하면 exit 2와 그 파일이 찍히는지 본다. helper는 경로 경계· 빈 폴더를 단위로 본다. timeout은 desktop에서 잰 가장 긴 값(test:unit 1,038 ms)이다. design-system 쪽 두 시험(가장 긴 719 ms)은 기존 describe의 3,540 ms 안이다. RED·GREEN은 PR 본문에 적는다. Refs: REV-FE-0002
228 lines
7.7 KiB
TypeScript
228 lines
7.7 KiB
TypeScript
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
|
import { designSystemReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import { fixtureRejectionFailure } from "./lib/fixture-rejection.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,
|
|
SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER,
|
|
} from "../src/presentation/design-system/tokens/token-contract.ts";
|
|
import {
|
|
firstFontFamilyFailures,
|
|
focusContrastFailures,
|
|
hueMixFailures,
|
|
rawSemanticColourFailures,
|
|
focusOffsetFailures,
|
|
inlineStyleFailures,
|
|
rawStyleValueFailures,
|
|
styleSheetColourFailures,
|
|
tokenRedefinitionFailures,
|
|
undeclaredComponentTokenFailures,
|
|
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}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every style sheet under src/, not only the ones theme.css imports: a
|
|
// feature's own CSS is a style sheet too (1101/12-03).
|
|
const tokenFileSet = new Set<string>(Object.values(tokenFiles));
|
|
const styleFiles = (await readdir("src", { recursive: true }))
|
|
.filter((file) => file.endsWith(".css"))
|
|
.map((file) => path.join("src", file))
|
|
.filter((file) => !tokenFileSet.has(file))
|
|
.sort();
|
|
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 }));
|
|
if (!tokenFileSet.has(file)) {
|
|
failures.push(
|
|
...rawStyleValueFailures({ file, source }),
|
|
...styleSheetColourFailures({ file, source }),
|
|
...focusOffsetFailures({ file, source }),
|
|
);
|
|
}
|
|
}
|
|
const tokenNames = new Set(
|
|
cssSources
|
|
.filter(({ file }) => tokenFileSet.has(file))
|
|
.flatMap(({ source }) => [...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1])),
|
|
);
|
|
for (const { file, source } of cssSources) {
|
|
if (!tokenFileSet.has(file)) failures.push(...tokenRedefinitionFailures({ file, source }, tokenNames));
|
|
}
|
|
|
|
const semanticSource = await readFile(tokenFiles.semantic, "utf8");
|
|
failures.push(
|
|
...rawSemanticColourFailures({ file: tokenFiles.semantic, source: semanticSource }),
|
|
);
|
|
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),
|
|
),
|
|
...unreadTokenFailures(
|
|
REQUIRED_SEMANTIC_TOKENS.filter(
|
|
(token) => !SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER.includes(token),
|
|
),
|
|
cssSources.filter(({ file }) => file !== tokenFiles.semantic),
|
|
"semantic",
|
|
),
|
|
...undeclaredComponentTokenFailures(
|
|
{ file: tokenFiles.component, source: await readFile(tokenFiles.component, "utf8") },
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
),
|
|
...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}`);
|
|
}
|
|
failures.push(...hueMixFailures({ file, source }), ...inlineStyleFailures({ file, source }));
|
|
}
|
|
|
|
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,
|
|
});
|
|
|
|
// Every fixture file must be rejected by a rule of its own (REV-FE-0002).
|
|
const unrejectedFixtures = fixtureMode
|
|
? fixtureRejectionFailure("Design system", sources, failures)
|
|
: undefined;
|
|
if (unrejectedFixtures) {
|
|
process.stderr.write(unrejectedFixtures);
|
|
process.exit(2);
|
|
}
|
|
|
|
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`,
|
|
);
|