diff --git a/.claude/skills/fe-design-system/SKILL.md b/.claude/skills/fe-design-system/SKILL.md index a9ee5c73..d6c84dfe 100644 --- a/.claude/skills/fe-design-system/SKILL.md +++ b/.claude/skills/fe-design-system/SKILL.md @@ -39,7 +39,7 @@ paths: 7. 컴포넌트 API를 열어 둔다: 날 색 prop, vendor 타입 노출, 무제한 `as`, 범위 없는 `className`. — `docs/design/2026-07-26-design-system-platform-design.md` 11절 4단계, 13절 8. primitive가 API·query·인증·저장소를 직접 부른다. pattern·template도 use case를 고르지 않고 상태와 callback을 props로 받는다. — 같은 문서 2절 9. 세 번째 사용 사례가 나오기 전에 제품 전용 조합을 primitive로 올린다. — 같은 문서 2절 -10. 시각 골든을 그냥 다시 찍는다. 골든은 코드 리뷰 대상이다. Chromium 하나, Linux, 글꼴 고정(`tests/visual/fonts.conf`)이고 허용 차이는 절대 픽셀 수다. 비율 허용이 1천 px 넘는 회귀를 통과시킨 일이 있어 절대 수로 바꿨다. 실패 screenshot은 시각 회귀가 아니다. — `playwright.visual.config.ts`, `docs/design/2026-07-26-design-system-platform-design.md` 10.3절 +10. 시각 골든을 그냥 다시 찍는다. 골든은 코드 리뷰 대상이다. Chromium 하나, Linux, 글꼴 고정(`tests/visual/fonts.conf`)이고 허용 차이는 절대 픽셀 수(`maxDiffPixels`)이고, 한 픽셀의 색 허용치는 0.05다(시각 spec의 `GOLDEN`). 비율 허용이 1천 px 넘는 회귀를, 기본 색 허용치 0.2가 위험 표면의 색상 변경을 통과시킨 일이 있다. 실패 screenshot은 시각 회귀가 아니다. — `playwright.visual.config.ts`, `docs/design/2026-07-26-design-system-platform-design.md` 10.3절 11. 골든이 그리는 범위를 넘겨 짐작한다. 골든은 셸·홈·플랫폼 구성·갤러리 story만 찍고 기능 영역은 가린다. 새 primitive·상태는 갤러리 story에 넣어야 골든에 든다. — `tests/visual/platform.visual.spec.ts`, `PRODUCT.md` 「Capabilities and Constraints」 12. 디자인 시스템이 side effect를 갖거나 무거운 것을 끌어와 초기 청크에 실린다. — `docs/work/reference/defect-patterns.md` B3, `tests/unit/design-system-initial-chunk.test.ts` diff --git a/tests/unit/visual-golden-threshold.test.ts b/tests/unit/visual-golden-threshold.test.ts new file mode 100644 index 00000000..feb10f8c --- /dev/null +++ b/tests/unit/visual-golden-threshold.test.ts @@ -0,0 +1,28 @@ +import { readFile, readdir } from "node:fs/promises"; +import path from "node:path"; + +import { describe, expect, it } from "vitest"; + +/** + * 1112/04-11. Playwright's colour threshold 0.2 let a danger surface turn + * green and still match its golden. tests/visual/platform.visual.spec.ts + * passes `GOLDEN` (threshold 0.05) to each screenshot; a new screenshot that + * leaves it out falls back to 0.2. + */ +describe("visual golden colour threshold", () => { + it("passes GOLDEN to every screenshot of the visual specs", async () => { + const folder = "tests/visual"; + const specs = (await readdir(folder)).filter((file) => file.endsWith(".spec.ts")); + const calls = ( + await Promise.all(specs.map(async (file) => ({ file, source: await readFile(path.join(folder, file), "utf8") }))) + ).flatMap(({ file, source }) => + source + .split("toHaveScreenshot(") + .slice(1) + .map((rest) => ({ file, args: rest.slice(0, rest.indexOf(");")) })), + ); + + expect(calls.length).toBeGreaterThan(0); + expect(calls.filter(({ args }) => !/\bGOLDEN\b/u.test(args)).map(({ file, args }) => `${file}: ${args.trim()}`)).toEqual([]); + }); +}); diff --git a/tests/visual/platform.visual.spec.ts b/tests/visual/platform.visual.spec.ts index 182b19e3..c34b810b 100644 --- a/tests/visual/platform.visual.spec.ts +++ b/tests/visual/platform.visual.spec.ts @@ -30,6 +30,16 @@ async function openGalleryStory(page: Page, storyId: string, title: string) { await expect(page.getByRole("heading", { level: 1 })).toHaveText(title); } +/** + * 1112/04-11. How far one pixel's colour may move before it counts as + * changed (pixelmatch's YIQ distance; Playwright's default is 0.2). At 0.2 a + * danger surface turned green (hue 25 to 145) and the dark danger colour one + * palette step darker both passed the goldens. 0.05 fails the first; a clean + * build still differs by 0 px. Every screenshot below takes it; the pixel + * count `maxDiffPixels` stays in playwright.visual.config.ts. + */ +const GOLDEN = Object.freeze({ threshold: 0.05 }); + /** `toHaveScreenshot` takes a stylesheet only as a file; a tag does the same. */ async function hide(page: Page, css: string) { if (css !== "") await page.addStyleTag({ content: css }); @@ -75,6 +85,7 @@ test("wide application shell visual contract", async ({ page }) => { await expectRouteHeading(page, "Clean Architecture Frontend"); await hide(page, WITHOUT_FEATURE_LINKS); await expect(page).toHaveScreenshot("app-shell-wide-light.png", { + ...GOLDEN, fullPage: true, }); }); @@ -88,6 +99,7 @@ test("compact drawer and pseudo-locale visual contract", async ({ page }) => { await expect(page.locator(".ui-drawer")).toHaveJSProperty("open", true); await hide(page, WITHOUT_FEATURE_LINKS); await expect(page).toHaveScreenshot("app-shell-compact-pseudo-drawer.png", { + ...GOLDEN, fullPage: true, }); }); @@ -103,6 +115,7 @@ test.describe("in the dark color scheme", () => { await expect(page.locator("html")).toHaveAttribute("data-theme", "dark"); await expect(page.getByRole("main")).toHaveScreenshot( "design-system-gallery-dark.png", + GOLDEN, ); }); }); @@ -114,6 +127,7 @@ test("loading empty error and access surfaces visual contract", async ({ await openGalleryStory(page, "platform-galleries--screen-states", "화면 상태"); await expect(page.getByRole("main")).toHaveScreenshot( "state-surfaces-light.png", + GOLDEN, ); }); @@ -135,5 +149,6 @@ test("platform composition overview visual contract", async ({ page }) => { await hide(page, WITHOUT_INSTALLED_FEATURE_SECTIONS); await expect(page.getByRole("main")).toHaveScreenshot( "platform-overview-light.png", + GOLDEN, ); });