-
Notifications
You must be signed in to change notification settings - Fork 18
[10/N] test(zh): add objective Chinese regression guards / 新增客观中文回归 CI 守卫 #841
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
Open
edwingao28
wants to merge
8
commits into
master
Choose a base branch
from
feat/zh-objective-ci-guard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc14e04
test(zh): enforce objective localization invariants
edwingao28 0edae46
fix(zh): harden objective localization guards
edwingao28 28df724
fix(zh): close objective guard parser gaps
edwingao28 4752152
fix(zh): protect GPU-hour copy invariants
edwingao28 a687050
fix(zh): complete protected-unit parsing
edwingao28 ef3893a
fix(zh): tokenize MDX attribute expressions
edwingao28 4393f7a
fix(zh): parse JSX in MDX attributes
edwingao28 cdacfdc
fix(zh): absorb rebased master content into guard exceptions and hard…
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,109 @@ | ||
| #!/usr/bin/env bun | ||
| import { execFileSync } from 'node:child_process'; | ||
|
|
||
| import { compareEnglishSurfaces } from '../src/lib/zh-objective-guard'; | ||
|
|
||
| interface Options { | ||
| readonly chineseOnly: boolean; | ||
| readonly base: string; | ||
| readonly head: string; | ||
| } | ||
|
|
||
| function optionValue(args: readonly string[], name: string): string | undefined { | ||
| const index = args.indexOf(name); | ||
| return index === -1 ? undefined : args[index + 1]; | ||
| } | ||
|
|
||
| function parseOptions(args: readonly string[]): Options { | ||
| const chineseOnly = args.includes('--chinese-only'); | ||
| const base = optionValue(args, '--base') ?? process.env.ZH_GUARD_BASE_SHA ?? ''; | ||
| const head = optionValue(args, '--head') ?? process.env.ZH_GUARD_HEAD_SHA ?? ''; | ||
| if (!chineseOnly || !base || !head) { | ||
| throw new Error( | ||
| 'Usage: check-zh-chinese-only.ts --chinese-only --base <base-sha> --head <head-sha>', | ||
| ); | ||
| } | ||
| return { chineseOnly, base, head }; | ||
| } | ||
|
|
||
| function git(args: readonly string[]): string { | ||
| return execFileSync('git', args, { encoding: 'utf8' }).trim(); | ||
| } | ||
|
|
||
| function sourceAt(revision: string, file: string): string { | ||
| if (!file) return ''; | ||
| try { | ||
| return execFileSync('git', ['show', `${revision}:${file}`], { | ||
| encoding: 'utf8', | ||
| stdio: ['ignore', 'pipe', 'ignore'], | ||
| }); | ||
| } catch { | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| interface ChangedFile { | ||
| readonly baseFile: string; | ||
| readonly headFile: string; | ||
| } | ||
|
|
||
| function changedFiles(base: string, head: string): ChangedFile[] { | ||
| const raw = execFileSync( | ||
| 'git', | ||
| [ | ||
| 'diff', | ||
| '--name-status', | ||
| '-z', | ||
| '--find-renames', | ||
| '--diff-filter=ACMRTD', | ||
| `${base}...${head}`, | ||
| '--', | ||
| ':(top)packages/app', | ||
| ], | ||
| { encoding: 'utf8' }, | ||
| ); | ||
| const fields = raw.split('\0'); | ||
| if (fields.at(-1) === '') fields.pop(); | ||
| const changed: ChangedFile[] = []; | ||
| for (let index = 0; index < fields.length;) { | ||
| const status = fields[index++]; | ||
| if (status.startsWith('R') || status.startsWith('C')) { | ||
| changed.push({ baseFile: fields[index++], headFile: fields[index++] }); | ||
| continue; | ||
| } | ||
| const file = fields[index++]; | ||
| changed.push({ | ||
| baseFile: status === 'A' ? '' : file, | ||
| headFile: status === 'D' ? '' : file, | ||
| }); | ||
| } | ||
| return changed; | ||
| } | ||
|
|
||
| const options = parseOptions(process.argv.slice(2)); | ||
| const mergeBase = git(['merge-base', options.base, options.head]); | ||
| const files = changedFiles(mergeBase, options.head); | ||
| const violations = files.flatMap(({ baseFile, headFile }) => { | ||
| const baseSource = sourceAt(mergeBase, baseFile); | ||
| const headSource = sourceAt(options.head, headFile); | ||
| const preferredFile = headFile || baseFile; | ||
| const preferred = compareEnglishSurfaces(preferredFile, baseSource, headSource); | ||
| if (preferred.length > 0 || baseFile === headFile || !baseFile) return preferred; | ||
| return compareEnglishSurfaces(baseFile, baseSource, headSource); | ||
| }); | ||
|
|
||
| if (violations.length > 0) { | ||
| console.error( | ||
| [ | ||
| 'Chinese-only mode found changed English bytes:', | ||
| ...violations.map((violation) => ` ${violation.file}: ${violation.detail}`), | ||
| '', | ||
| 'Remove the chinese-copy-only label when the PR intentionally changes English copy.', | ||
| ].join('\n'), | ||
| ); | ||
| process.exitCode = 1; | ||
| } else { | ||
| console.log( | ||
| `Chinese-only English-byte guard passed for ${files.length} changed app file(s) against merge base ${mergeBase}.`, | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Unconditional full git fetch penalizes all PR runs
Low Severity
The
fetch-depth: 0checkout applies unconditionally to every workflow run, fetching the entire git history even though only the conditional "Preserve English bytes" step (gated bychinese-copy-onlylabel) needs deep history. The vast majority of PR runs—triggered byopened,synchronize, orready_for_review—only run typecheck and unit tests, which need only a shallow clone. Combined with the newlabeled/unlabeledactivity types causing extra workflow triggers for any label change on matching PRs, this increases CI time and cost across all runs.Reviewed by Cursor Bugbot for commit 3cc309d. Configure here.