문제: UI-03 규칙은 source.includes(`var(${token}`)로 독자를 찾는다.
"var(--field-border"가 var(--field-border-invalid) 안에도 있어서, 독자가
0곳이던 --field-border를 통과시켰다. 주석 안의 var(--x)도 독자로 셌다.
그리고 이번 브랜치의 디자인 규칙 4개(포커스 대비, oklab 혼합, 토큰
사용, 첫 글꼴)는 스크립트 본문에 바로 있어서, 규칙을 꺼도 잡는 테스트가
없었다(12-02).
고른 방법:
- 규칙 4개를 scripts/lib/design-system-rules.ts의 순수 함수로 옮긴다.
입력은 CSS 글자와 토큰 맵이고 출력은 실패 메시지다. 메시지 문구와
순서는 그대로다.
- 토큰 독자는 var(--name) 또는 var(--name, ...)처럼 이름 전체가 맞아야
한다. "var"는 대소문자를 무시하고, 사용자 정의 속성 이름은 CSS 규칙
대로 대소문자를 구분한다.
- 토큰 사용 규칙과 oklab 혼합 규칙은 CSS 주석을 지우고 본다(리뷰 probe
B5 우회, B12 오탐).
- oklab 혼합 규칙은 대소문자를 무시한다(B1 `in OKLCH` 우회). CSS
키워드는 대소문자를 구분하지 않는다.
- ui-design-audit.md의 UI-03 행에 다섯 번째 토큰을 적는다.
버린 대안: 12-02가 제안한 --root 인자와 CSS 음성 fixture 폴더. 규칙별
검출을 증명하려면 어차피 실패 메시지를 단언하는 테스트가 필요하고,
순수 함수 단위 테스트가 fixture 파일 없이 같은 것을 증명한다. 게이트의
--fixture 모드와 산출물 스키마는 바꾸지 않았다.
위험·한계:
- 주석 제거는 정규식이라 따옴표 문자열 안의 "/*"를 주석 시작으로
본다. 지금 CSS에는 없다.
- 12-03의 나머지 우회(그라디언트, TSX 인라인, base.css 재정의,
outline-offset 0, feature CSS)와 12-04의 오탐(-apple-system, deg,
알파, color-mix 표면)은 그대로다. 포커스·글꼴 규칙은 주석을 지우지
않는다.
- 게이트의 check:design-system:fixture는 여전히 TSX fixture 두 개만으로
"기대 실패"를 채운다. CSS 규칙 회귀는 test:unit이 잡는다.
검증:
- RED(규칙을 동작 그대로 옮긴 상태): tests/unit/design-system-rules.test.ts
11개 중 5개 실패. "does not count a longer token that starts with the
same name"이 "expected [] to deeply equal [ Array(1) ]"로 실패했다.
나머지 4개는 대문자 OKLCH, 주석 안 혼합, VAR( --x , ...) 형태, 주석
안 독자.
- 고친 검사를 앞 커밋 전 CSS(402e1db)에 돌리면 "component token
--field-border is defined but no style reads it"으로 실패했다.
- GREEN: 같은 파일 11/11 통과. tests/unit 166파일 2364개 통과.
- 변이: 대비 기준 < 0, 혼합 정규식 무력화, 토큰·글꼴 판정 무조건
통과로 바꾸면 규칙마다 실패 테스트가 하나 이상 깨졌다(7/11 실패).
- check:design-system PASS, --fixture는 기대대로 실패. tsc(app, node,
test) 통과, 바꾼 파일 eslint 통과, verify-documentation PASS_SCOPED.
Refs: docs/reviews/2026-11-01-maturity-review/12-guardrails-ci.md 12-01, 12-02
104 lines
3.8 KiB
TypeScript
104 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
FOCUS_RING_BACKGROUNDS,
|
|
firstFontFamilyFailures,
|
|
focusContrastFailures,
|
|
hueMixFailures,
|
|
unreadTokenFailures,
|
|
} from "../../scripts/lib/design-system-rules.ts";
|
|
|
|
const css = (source: string) => ({ file: "probe.css", source });
|
|
|
|
describe("design system rules", () => {
|
|
describe("UI-01 focus ring contrast", () => {
|
|
const tokens = (focus: string) =>
|
|
new Map([
|
|
...FOCUS_RING_BACKGROUNDS.map((surface) => [surface, "oklch(1 0 0)"] as const),
|
|
["--color-focus", focus],
|
|
]);
|
|
|
|
it("fails a focus colour below 3:1 against a surface", () => {
|
|
// The light focus ring before UI-01.
|
|
expect(focusContrastFailures("light", tokens("oklch(0.72 0.16 225)"))).toContainEqual(
|
|
expect.stringMatching(/^light --color-focus contrast 2\.\d\d:1 against --color-panel is below 3:1$/),
|
|
);
|
|
});
|
|
|
|
it("passes a focus colour at 3:1 or more on every surface", () => {
|
|
expect(focusContrastFailures("light", tokens("oklch(0.52 0.15 230)"))).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("UI-02 colour mixing space", () => {
|
|
it("fails a hue-based mixing space", () => {
|
|
expect(hueMixFailures(css("a { color: color-mix(in oklch, red, blue); }"))).toEqual([
|
|
"probe.css mixes colours in oklch; use oklab",
|
|
]);
|
|
});
|
|
|
|
it("fails it in upper case, since CSS keywords ignore case", () => {
|
|
expect(hueMixFailures(css("a { color: COLOR-MIX(in OKLCH, red, blue); }"))).toEqual([
|
|
"probe.css mixes colours in OKLCH; use oklab",
|
|
]);
|
|
});
|
|
|
|
it("passes oklab, and old code left in a comment", () => {
|
|
expect(
|
|
hueMixFailures(
|
|
css("/* was color-mix(in oklch, red, blue) */ a { color: color-mix(in oklab, red, blue); }"),
|
|
),
|
|
).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("UI-03 component token readers", () => {
|
|
const tokens = ["--field-border", "--field-border-invalid"];
|
|
|
|
// 12-01: "var(--field-border" is also the start of
|
|
// "var(--field-border-invalid)".
|
|
it("does not count a longer token that starts with the same name", () => {
|
|
expect(
|
|
unreadTokenFailures(tokens, [css("a { border-color: var(--field-border-invalid); }")]),
|
|
).toEqual(["component token --field-border is defined but no style reads it"]);
|
|
});
|
|
|
|
it("counts var(--x) and var(--x, fallback), with any case for var", () => {
|
|
for (const source of [
|
|
"a { border-color: var(--field-border); }",
|
|
"a { border: 1px solid VAR( --field-border , red); }",
|
|
]) {
|
|
expect(unreadTokenFailures(["--field-border"], [css(source)])).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it("does not count a name in another case, since custom properties are case-sensitive", () => {
|
|
expect(unreadTokenFailures(["--field-border"], [css("a { color: var(--Field-Border); }")]))
|
|
.toEqual(["component token --field-border is defined but no style reads it"]);
|
|
});
|
|
|
|
it("does not count a read inside a comment", () => {
|
|
expect(unreadTokenFailures(["--field-border"], [css("/* var(--field-border) */")])).toEqual([
|
|
"component token --field-border is defined but no style reads it",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("UI-05 first font family", () => {
|
|
it("fails a named font that nothing loads", () => {
|
|
expect(firstFontFamilyFailures("Inter, system-ui, sans-serif", [])).toEqual([
|
|
'--font-sans starts with "Inter", which is neither a generic family nor loaded by @font-face',
|
|
]);
|
|
});
|
|
|
|
it("passes a generic family, or a family loaded by @font-face", () => {
|
|
expect(firstFontFamilyFailures("system-ui, sans-serif", [])).toEqual([]);
|
|
expect(
|
|
firstFontFamilyFailures('"Brand Sans", sans-serif', [
|
|
css('@font-face { font-family: "Brand Sans"; src: url(brand.woff2); }'),
|
|
]),
|
|
).toEqual([]);
|
|
});
|
|
});
|
|
});
|