Skip to content

Commit 20f7148

Browse files
committed
fix(WebServer): make Chinese text scanner fail tests when findings exist
- scan_chinese.py: exclude coverage dir, add allowlist for language display names, return finding count instead of None - run_tests.py: check scanner return value and fail if count > 0
1 parent fcea691 commit 20f7148

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

Tools/WebServer/tests/run_tests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ def run_scan_chinese():
3535

3636
from scan_chinese import main as scan_main
3737

38-
scan_main()
39-
return True # Scanner always succeeds, just reports findings
38+
count = scan_main()
39+
if count > 0:
40+
print(f"\n⚠️ Found {count} hardcoded Chinese text instances!")
41+
return False
42+
return True
4043

4144

4245
def run_api_check():

Tools/WebServer/tests/scan_chinese.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ def scan_directory(root_dir):
4747
results = {}
4848

4949
# Directories and files to exclude (i18n locale files are expected to have Chinese)
50-
exclude_dirs = {"locales", "node_modules", "__pycache__", ".git"}
50+
exclude_dirs = {"locales", "node_modules", "__pycache__", ".git", "coverage"}
5151
exclude_files = {
5252
"zh-CN.js",
5353
"zh-TW.js",
5454
"config_schema.py",
5555
} # config_schema.py has language option labels
5656

57+
# Allowlist: patterns that are acceptable Chinese text
58+
# Language display names should always show in their native script
59+
allowlist = {"简体中文", "繁體中文"}
60+
5761
for root, dirs, files in os.walk(root_dir):
5862
# Skip excluded directories
5963
dirs[:] = [d for d in dirs if d not in exclude_dirs]
@@ -66,6 +70,8 @@ def scan_directory(root_dir):
6670
if file.endswith((".js", ".html", ".py")):
6771
file_path = os.path.join(root, file)
6872
findings = scan_file(file_path)
73+
# Filter out allowlisted text
74+
findings = [f for f in findings if f["text"] not in allowlist]
6975
if findings:
7076
results[file_path] = findings
7177

@@ -85,7 +91,7 @@ def main():
8591

8692
if not results:
8793
print("No Chinese text found in .js, .html, and .py files.")
88-
return
94+
return 0
8995

9096
total_files = len(results)
9197
total_findings = sum(len(findings) for findings in results.values())
@@ -110,6 +116,7 @@ def main():
110116
print(
111117
f"Summary: {total_files} files with Chinese text, {total_findings} instances total."
112118
)
119+
return total_findings
113120

114121

115122
if __name__ == "__main__":

0 commit comments

Comments
 (0)