Repository navigation
fix(script): honor grey exceptions on Windows #63619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<string, string>, 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", | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be dropped: the fix is one line, and this test passes on Linux both with and without the fix (I checked by restoring the base
script/check-greys.ts), because the temp files only ever have native/paths here. It also copies the script into a temp folder and starts a separate process to run it, and since--jsonalways exits 0, theexitCodecheck below proves nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended for the Windows full-tier runs, not the Linux-only PR run. I verified it on Windows with Bun 1.4.4: restoring the base checker makes the JSON outcome assertion fail, with both exempt paths reported as
problem: not on the scale. With the fix, both report their expected exception reasons. The zero exit check only guards subprocess success; it is not the regression assertion. The second case separately checks exit 1 for a non-exempt file. I kept the real CLI tests to cover that platform behavior without adding a production test API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's fair.
check-test.ymldoes run the unit tests on Windows for pushes, nightly runs and the release gate, so the JSON outcome check would catch this bug there, even though it can't on the Linux pull-request run. I can't run it on Windows myself, so I'm relying on your result for that. Understood on the exit code: in--jsonmode the script always exits 0, so that check only confirms the process ran. My remaining point is size: 78 lines that copy the script into a temp folder and start a separate process, to guard a one-line fix. Whether that's worth keeping is up to the maintainers.