From 25b83c2ec9936424134b7a8c99bda96ea6628303 Mon Sep 17 00:00:00 2001 From: Viraj Choudhary <70713801+virajchoudhary@users.noreply.github.com> Date: Fri, 13 Nov 2026 04:18:28 +0530 Subject: [PATCH] fix(script): honor grey exceptions on Windows Closes #63615 --- packages/script/test/check-greys.test.ts | 78 ++++++++++++++++++++++++ script/check-greys.ts | 3 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 packages/script/test/check-greys.test.ts diff --git a/packages/script/test/check-greys.test.ts b/packages/script/test/check-greys.test.ts new file mode 100644 index 0000000000000..9fa717388568d --- /dev/null +++ b/packages/script/test/check-greys.test.ts @@ -0,0 +1,78 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { copyFile, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises" +import { tmpdir } from "node:os" +import path from "node:path" + +const directories: string[] = [] + +afterEach(async () => { + await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true }))) +}) + +describe("check-greys", () => { + test("honors declared path exceptions with Windows separators", async () => { + const result = await runChecker( + { + "services/site/src/component/font-share/share.css": ".share { color: #777777; }\n", + "services/site/src/style/token/color.css": ":root { --neutral: #777777; }\n", + }, + ["--json"], + ) + + expect(result.exitCode).toBe(0) + expect( + JSON.parse(result.stdout.toString()) + .entries.map((entry: { outcome: string }) => entry.outcome) + .sort(), + ).toEqual( + [ + "exception: Font share cards: exported images", + "exception: Legacy tokens: to remove when the dropdown, language picker, 404 and limits graph move to site tokens", + ].sort(), + ) + }) + + test("still rejects greys outside declared path exceptions", async () => { + const result = await runChecker({ + "services/site/src/component/site/regular.css": ".regular { color: #777777; }\n", + }) + + expect(result.exitCode).toBe(1) + expect(result.stderr.toString()).toContain("#777777 not on the scale") + }) +}) + +async function runChecker(stylesheets: Record, args: string[] = []) { + const directory = await mkdtemp(path.join(tmpdir(), "opencode-greys-")) + directories.push(directory) + + const checker = path.join(directory, "script", "check-greys.ts") + await mkdir(path.dirname(checker), { recursive: true }) + await copyFile(path.resolve(import.meta.dir, "../../../script/check-greys.ts"), checker) + + for (const [file, source] of Object.entries(stylesheets)) { + const target = path.join(directory, file) + await mkdir(path.dirname(target), { recursive: true }) + await writeFile(target, source) + } + + const home = path.join(directory, "home") + const temp = path.join(directory, "temp") + await Promise.all([mkdir(home), mkdir(temp)]) + + return Bun.spawnSync({ + cmd: [process.execPath, checker, ...args], + cwd: directory, + env: { + ...process.env, + HOME: home, + USERPROFILE: home, + TMP: temp, + TEMP: temp, + TMPDIR: temp, + PATH: `${path.dirname(process.execPath)}${path.delimiter}${process.env.PATH ?? ""}`, + }, + stdout: "pipe", + stderr: "pipe", + }) +} diff --git a/script/check-greys.ts b/script/check-greys.ts index d1669c8065b64..f11b7492a2937 100644 --- a/script/check-greys.ts +++ b/script/check-greys.ts @@ -68,7 +68,8 @@ const entries = ( await Promise.all( files.map(async (file) => { const source = await Bun.file(path.join(repo(), file)).text() - const exception = EXCEPTIONS.find(([re]) => re.test(file))?.[1] + const normalizedFile = file.replaceAll(path.sep, "/") + const exception = EXCEPTIONS.find(([re]) => re.test(normalizedFile))?.[1] const allowed = allowedRanges(source) return declarations(source).flatMap((decl) => neutrals(decl.value).map((hex) => ({