mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
chore(audit): generator code bundle no longer exempt from Han scan
The rebuilt bundle ships translated strings, so westernization_audit.sh now scans generator/assets + index.html as live source (allowlisting the one third-party opentype.js LCID font-name table line). The exception narrows to generator/static device data, which the firmware consumes byte-for-byte. westernization.md documents the checkout location and rebuild flow.
This commit is contained in:
parent
39ba5efd1b
commit
13a627af6b
2 changed files with 76 additions and 42 deletions
|
|
@ -5,6 +5,20 @@ set -euo pipefail
|
||||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
cd "$ROOT_DIR"
|
cd "$ROOT_DIR"
|
||||||
|
|
||||||
|
# Exception policy (agreed 2026-10-12):
|
||||||
|
# - Append-only Liquibase history under
|
||||||
|
# main/manager-api/src/main/resources/db/changelog keeps its historical
|
||||||
|
# Chinese seed/updates (a fresh install is migrated + cleaned to English by
|
||||||
|
# the append-only 202610111200.sql changeset).
|
||||||
|
# - main/manager-web/public/generator/static is functional device data
|
||||||
|
# (charset codepoint tables, CJK glyph tables, emoji gifs, wakeword model
|
||||||
|
# blobs) consumed byte-for-byte by the firmware toolchain: exempt.
|
||||||
|
# - The generator CODE bundle (generator/assets/**, generator/index.html) is
|
||||||
|
# rebuilt from the translated generator source and is NOT exempt; it is
|
||||||
|
# scanned like live source. One allowlisted artefact is tolerated: the
|
||||||
|
# opentype.js LCID -> BCP47 table (e.g. 1028 -> zh TW locale id), a font
|
||||||
|
# parsing table, not user-facing text.
|
||||||
|
|
||||||
if ! command -v rg >/dev/null 2>&1; then
|
if ! command -v rg >/dev/null 2>&1; then
|
||||||
if ! command -v python3 >/dev/null 2>&1; then
|
if ! command -v python3 >/dev/null 2>&1; then
|
||||||
echo "ripgrep (rg) or python3 is required for this audit." >&2
|
echo "ripgrep (rg) or python3 is required for this audit." >&2
|
||||||
|
|
@ -20,6 +34,8 @@ root = Path(".")
|
||||||
locale_pattern = "zh-" + "CN|" + "zh-" + "TW"
|
locale_pattern = "zh-" + "CN|" + "zh-" + "TW"
|
||||||
content_pattern = re.compile(r"[\u4e00-\u9fff]|" + locale_pattern)
|
content_pattern = re.compile(r"[\u4e00-\u9fff]|" + locale_pattern)
|
||||||
path_pattern = re.compile(r"[\u4e00-\u9fff]")
|
path_pattern = re.compile(r"[\u4e00-\u9fff]")
|
||||||
|
# Third-party LCID -> BCP47 mapping in vendored opentype.js (font name tables).
|
||||||
|
allowline_pattern = re.compile(r"\d+:\"zh-(?:CN|TW)\"")
|
||||||
|
|
||||||
content_skip_dirs = {
|
content_skip_dirs = {
|
||||||
".git",
|
".git",
|
||||||
|
|
@ -33,13 +49,10 @@ content_skip_exts = {
|
||||||
".ttf", ".woff", ".woff2", ".mp3", ".wav", ".opus", ".pdf",
|
".ttf", ".woff", ".woff2", ".mp3", ".wav", ".opus", ".pdf",
|
||||||
".ico", ".svg",
|
".ico", ".svg",
|
||||||
}
|
}
|
||||||
main_exceptions = (
|
changelog_exception = "main/manager-api/src/main/resources/db/changelog"
|
||||||
"main/manager-api/src/main/resources/db/changelog",
|
generator_root = "main/manager-web/public/generator"
|
||||||
"main/manager-web/public/generator",
|
generator_data_exception = generator_root + "/static"
|
||||||
)
|
live_exceptions = (changelog_exception, generator_data_exception)
|
||||||
generated_exception_paths = (
|
|
||||||
"main/manager-web/public/generator",
|
|
||||||
)
|
|
||||||
path_skip_prefixes = (
|
path_skip_prefixes = (
|
||||||
".git",
|
".git",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|
@ -73,7 +86,7 @@ def candidate_files():
|
||||||
except Exception:
|
except Exception:
|
||||||
return [path for path in root.rglob("*") if path.is_file()]
|
return [path for path in root.rglob("*") if path.is_file()]
|
||||||
|
|
||||||
def scan_paths(predicate):
|
def scan_paths(predicate, allowlist=False):
|
||||||
matches = []
|
matches = []
|
||||||
for path in candidate_files():
|
for path in candidate_files():
|
||||||
if not path.is_file():
|
if not path.is_file():
|
||||||
|
|
@ -87,11 +100,13 @@ def scan_paths(predicate):
|
||||||
continue
|
continue
|
||||||
for line_no, line in enumerate(text.splitlines(), 1):
|
for line_no, line in enumerate(text.splitlines(), 1):
|
||||||
if content_pattern.search(line):
|
if content_pattern.search(line):
|
||||||
|
if allowlist and allowline_pattern.search(line):
|
||||||
|
continue
|
||||||
matches.append((path_text, line_no, line[:240]))
|
matches.append((path_text, line_no, line[:240]))
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
section("Live Source And Docs Audit")
|
section("Live Source And Docs Audit")
|
||||||
live_matches = scan_paths(lambda path_text: not is_under(path_text, main_exceptions))
|
live_matches = scan_paths(lambda path_text: not is_under(path_text, live_exceptions), allowlist=True)
|
||||||
if live_matches:
|
if live_matches:
|
||||||
for path_text, line_no, line in live_matches:
|
for path_text, line_no, line in live_matches:
|
||||||
print(f"{path_text}:{line_no}:{line}")
|
print(f"{path_text}:{line_no}:{line}")
|
||||||
|
|
@ -102,7 +117,7 @@ else:
|
||||||
live_status = 0
|
live_status = 0
|
||||||
|
|
||||||
section("Historical Changelog Exceptions")
|
section("Historical Changelog Exceptions")
|
||||||
changelog_matches = scan_paths(lambda path_text: is_under(path_text, (main_exceptions[0],)))
|
changelog_matches = scan_paths(lambda path_text: is_under(path_text, (changelog_exception,)))
|
||||||
if changelog_matches:
|
if changelog_matches:
|
||||||
print(f"{len(changelog_matches)} match(es). Showing up to 40:")
|
print(f"{len(changelog_matches)} match(es). Showing up to 40:")
|
||||||
for path_text, line_no, line in changelog_matches[:40]:
|
for path_text, line_no, line in changelog_matches[:40]:
|
||||||
|
|
@ -111,21 +126,19 @@ if changelog_matches:
|
||||||
print("... truncated ...")
|
print("... truncated ...")
|
||||||
print("\nHistorical changelog exceptions detected above.")
|
print("\nHistorical changelog exceptions detected above.")
|
||||||
else:
|
else:
|
||||||
print("No matches.")
|
|
||||||
print("No historical changelog hits.")
|
print("No historical changelog hits.")
|
||||||
|
|
||||||
section("Generated Bundle Exceptions")
|
section("Vendored Device Data Exceptions")
|
||||||
generated_matches = scan_paths(lambda path_text: is_under(path_text, generated_exception_paths))
|
data_matches = scan_paths(lambda path_text: is_under(path_text, (generator_data_exception,)))
|
||||||
if generated_matches:
|
if data_matches:
|
||||||
print(f"{len(generated_matches)} match(es). Showing up to 40:")
|
print(f"{len(data_matches)} match(es). Showing up to 40:")
|
||||||
for path_text, line_no, line in generated_matches[:40]:
|
for path_text, line_no, line in data_matches[:40]:
|
||||||
print(f"{path_text}:{line_no}:{line}")
|
print(f"{path_text}:{line_no}:{line}")
|
||||||
if len(generated_matches) > 40:
|
if len(data_matches) > 40:
|
||||||
print("... truncated ...")
|
print("... truncated ...")
|
||||||
print("\nGenerated bundle exceptions detected above.")
|
print("\nVendored device data exceptions detected above (byte-exact data, not prose).")
|
||||||
else:
|
else:
|
||||||
print("No matches.")
|
print("No vendored device data hits.")
|
||||||
print("No generated bundle hits.")
|
|
||||||
|
|
||||||
section("Path Audit")
|
section("Path Audit")
|
||||||
path_matches = []
|
path_matches = []
|
||||||
|
|
@ -149,8 +162,9 @@ section("Summary")
|
||||||
if live_status == 0 and path_status == 0:
|
if live_status == 0 and path_status == 0:
|
||||||
print("Westernization baseline is clean outside intentional exceptions.")
|
print("Westernization baseline is clean outside intentional exceptions.")
|
||||||
print("Intentional exceptions:")
|
print("Intentional exceptions:")
|
||||||
print("- append-only Liquibase history under main/manager-api/src/main/resources/db/changelog")
|
print("- append-only Liquibase history under " + changelog_exception)
|
||||||
print("- vendored generator bundle under main/manager-web/public/generator")
|
print("- vendored device data under " + generator_data_exception)
|
||||||
|
print("- opentype.js LCID table (1028:\"zh-" "TW\") inside the generator bundle")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print("Westernization baseline still has non-exempt findings.")
|
print("Westernization baseline still has non-exempt findings.")
|
||||||
|
|
@ -186,10 +200,13 @@ CONTENT_IGNORE=(
|
||||||
MAIN_IGNORE=(
|
MAIN_IGNORE=(
|
||||||
"${CONTENT_IGNORE[@]}"
|
"${CONTENT_IGNORE[@]}"
|
||||||
"!main/manager-api/src/main/resources/db/changelog/**"
|
"!main/manager-api/src/main/resources/db/changelog/**"
|
||||||
"!main/manager-web/public/generator/**"
|
"!main/manager-web/public/generator/static/**"
|
||||||
)
|
)
|
||||||
|
|
||||||
CONTENT_PATTERN='[\p{Han}]|zh-C''N|zh-T''W'
|
CONTENT_PATTERN='[\p{Han}]|zh-C''N|zh-T''W'
|
||||||
|
# Third-party LCID -> BCP47 mapping inside the vendored opentype.js font
|
||||||
|
# parser (e.g. LCID 1028 mapped to a zh TW locale id); font metadata, not text.
|
||||||
|
ALLOWLINE_PATTERN='[0-9]+:"zh-(CN|TW)"'
|
||||||
PATH_IGNORE=(
|
PATH_IGNORE=(
|
||||||
"./.git"
|
"./.git"
|
||||||
"./node_modules"
|
"./node_modules"
|
||||||
|
|
@ -257,7 +274,8 @@ show_limited_matches() {
|
||||||
|
|
||||||
section "Live Source And Docs Audit"
|
section "Live Source And Docs Audit"
|
||||||
collect_audit_roots
|
collect_audit_roots
|
||||||
if run_rg "$CONTENT_PATTERN" "${MAIN_IGNORE[@]}"; then
|
if matches="$(run_rg "$CONTENT_PATTERN" "${MAIN_IGNORE[@]}" | rg -v "$ALLOWLINE_PATTERN" || true)" && [[ -n "$matches" ]]; then
|
||||||
|
printf '%s\n' "$matches"
|
||||||
echo
|
echo
|
||||||
echo "Live source/doc audit: FAIL"
|
echo "Live source/doc audit: FAIL"
|
||||||
live_status=1
|
live_status=1
|
||||||
|
|
@ -277,16 +295,16 @@ else
|
||||||
echo "No historical changelog hits."
|
echo "No historical changelog hits."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
section "Generated Bundle Exceptions"
|
section "Vendored Device Data Exceptions"
|
||||||
if show_limited_matches \
|
if show_limited_matches \
|
||||||
"Generated bundle exceptions" \
|
"Vendored device data exceptions" \
|
||||||
"$CONTENT_PATTERN" \
|
"$CONTENT_PATTERN" \
|
||||||
main/manager-web/public/generator \
|
main/manager-web/public/generator/static \
|
||||||
-g '!**/*.png' -g '!**/*.jpg' -g '!**/*.jpeg'; then
|
-g '!**/*.png' -g '!**/*.jpg' -g '!**/*.jpeg'; then
|
||||||
echo
|
echo
|
||||||
echo "Generated bundle exceptions detected above."
|
echo "Vendored device data exceptions detected above (byte-exact data, not prose)."
|
||||||
else
|
else
|
||||||
echo "No generated bundle hits."
|
echo "No vendored device data hits."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
section "Path Audit"
|
section "Path Audit"
|
||||||
|
|
@ -310,7 +328,8 @@ if [[ "$live_status" -eq 0 && "$path_status" -eq 0 ]]; then
|
||||||
echo "Westernization baseline is clean outside intentional exceptions."
|
echo "Westernization baseline is clean outside intentional exceptions."
|
||||||
echo "Intentional exceptions:"
|
echo "Intentional exceptions:"
|
||||||
echo "- append-only Liquibase history under main/manager-api/src/main/resources/db/changelog"
|
echo "- append-only Liquibase history under main/manager-api/src/main/resources/db/changelog"
|
||||||
echo "- vendored generator bundle under main/manager-web/public/generator"
|
echo "- vendored device data under main/manager-web/public/generator/static"
|
||||||
|
echo "- opentype.js LCID font-name table inside the generator bundle"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,26 +142,34 @@ Actions:
|
||||||
|
|
||||||
## Generator Rule
|
## Generator Rule
|
||||||
|
|
||||||
Treat this as special:
|
The device-theme generator is a separate Vite/Vue app. Its built output is
|
||||||
|
vendored into this repo:
|
||||||
|
|
||||||
- `main/manager-web/public/generator/assets/**` is generated output
|
- `main/manager-web/public/generator/assets/**` is generated output
|
||||||
- `main/manager-web/public/generator/index.html` is tied to that output
|
- `main/manager-web/public/generator/index.html` is tied to that output
|
||||||
|
- `main/manager-web/public/generator/static/**` is functional device data
|
||||||
|
(charset codepoint tables, CJK font glyph tables, emoji gifs, wakeword
|
||||||
|
model blobs) shipped byte-for-byte to the firmware toolchain
|
||||||
|
|
||||||
Do not hand-edit the built bundle unless absolutely necessary.
|
Do not hand-edit the built bundle unless absolutely necessary.
|
||||||
|
|
||||||
Preferred flow:
|
The generator source repo is a separate checkout:
|
||||||
|
|
||||||
1. update generator source
|
- remote: `https://github.com/78/xiaozhi-assets-generator`
|
||||||
2. rebuild generator
|
(westernization branch, translated locales/comments, relative asset base)
|
||||||
3. sync rebuilt assets into `main/manager-web/public/generator`
|
- working copy during rebuild work: `/tmp/xiaozhi-assets-generator`
|
||||||
|
|
||||||
Generator source currently lives outside the main repo worktree during rebuild
|
Rebuild flow:
|
||||||
work:
|
|
||||||
|
|
||||||
- `/tmp/xiaozhi-assets-generator`
|
1. update generator source (never the bundle directly)
|
||||||
|
2. `cd web && npm run build` (default base `./` so the bundle works under
|
||||||
|
whatever path the console mounts it at, e.g. `/generator/`)
|
||||||
|
3. replace `main/manager-web/public/generator` with the fresh `web/dist`
|
||||||
|
4. run `./scripts/westernization_audit.sh`
|
||||||
|
|
||||||
If Han-script appears in the generated bundle, check generator source locales
|
If Han-script appears in the generated code bundle, fix the generator source
|
||||||
first before attempting bundle surgery.
|
first before attempting bundle surgery. The audit treats the code bundle as
|
||||||
|
live source; only `generator/static` data is exempt.
|
||||||
|
|
||||||
## Audit Workflow
|
## Audit Workflow
|
||||||
|
|
||||||
|
|
@ -174,12 +182,19 @@ Use the audit script after meaningful rebase batches:
|
||||||
What it enforces:
|
What it enforces:
|
||||||
|
|
||||||
- live source/docs must be clean of Han-script and Chinese locale tags
|
- live source/docs must be clean of Han-script and Chinese locale tags
|
||||||
|
- this includes the vendored generator code bundle
|
||||||
|
(`main/manager-web/public/generator/assets/**` and `index.html`)
|
||||||
- path names must be clean of Han-script
|
- path names must be clean of Han-script
|
||||||
|
|
||||||
Intentional exception zones:
|
Intentional exception zones:
|
||||||
|
|
||||||
- `main/manager-api/src/main/resources/db/changelog`
|
- `main/manager-api/src/main/resources/db/changelog` (append-only Liquibase
|
||||||
- `main/manager-web/public/generator/assets`
|
history; fresh installs are migrated and cleaned to English by the append
|
||||||
|
downstream changeset)
|
||||||
|
- `main/manager-web/public/generator/static/**` (functional device data shipped
|
||||||
|
byte-for-byte: charset codepoint lists, CJK glyph tables, wakeword blobs)
|
||||||
|
- one allowlisted line inside the generator bundle: the third-party opentype.js
|
||||||
|
LCID-to-BCP47 font-name table (it maps locale ids such as 1028)
|
||||||
|
|
||||||
If the audit fails outside those areas, fix the violations before moving on.
|
If the audit fails outside those areas, fix the violations before moving on.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue