fix(gates): close the BOM gate hole that let new files skip the check

The BOM gate claimed to stop BOMs from being stripped, but it only ever
inspected files that were already tracked AND already had a BOM. A new
file under a BOM-listed directory could be born without one and never
be noticed, because the scan never returned it and, even if it had, the
"no HEAD version" branch skipped it. Editing a listed file and losing
its BOM is a real accident that already happened once; creating one
without a BOM was the same accident with no safety net at all.

Measured before and after on the same untracked file with no BOM:

  before: checked 101 files, no drift, exit 0
  after:  FAIL, names the file, exit 1

The count of 101 was itself the symptom: with one more file present the
honest number is 102. The old code was not "silently passing a clean
tree", it was not looking.

The scan now includes untracked files, and a listed file with no HEAD
version must carry a BOM. Files that are tracked without a BOM keep
their historical pass so this does not flood existing code with
failures; instead the two that were listed but had no BOM were given one
so the list means what it says.

That exposed a conflict nobody had hit yet. The font file is generated,
and the generator rewrites it from scratch on every run, so a hand-added
BOM survived until the next regeneration and then vanished. The BOM gate
and the generated-fresh gate could not both pass. The generator now puts
the BOM back as its last step, idempotently, so the two gates agree and
the whole UI directory keeps its uniform encoding. Font content is
untouched: everything after the first three bytes is byte-identical.

The menu generator gains a real read-only mode. It previously had no
options at all and always rewrote its outputs; the arrows it printed
were accurate. That made it easy to mistake for a checker, since an
unchanged tree produces identical bytes and looks untouched. --check now
reports up to date or stale without writing anything, and the
registration tables are checked the same way. Default behaviour and
output are unchanged.

The telemetry page header no longer restates the board's input hardware
facts. They live in the IOBOARD README, which is where the board's
electrical behaviour belongs; the page keeps only what it alone can say:
that the output rows show the shadow register rather than contact
feedback, why an invalid sample draws -- instead of 分, and that these
twelve rows are not in the point table. One fact, one place.

The team rule for experiments now requires the file hash, the located
line number, and both runs. A report once cited a line number that did
not exist in the final file, which left no way to confirm which version
had actually been tested.
This commit is contained in:
2026-11-16 23:59:49 +08:00
parent 515db819ab
commit 12e0617909
14 changed files with 283 additions and 60 deletions
+26
View File
@@ -549,8 +549,34 @@ def main():
verify_coverage(OUT) # 生成后校验:字符集全部码位必须进字体(防静默丢字)
fix_trailing_newline(OUT) # 规范化末尾换行(pre-commit end-of-file-fixer)
normalize_project_conventions(OUT, args.size, args.bpp) # 对齐工程约定(文件头/包含路径/版本守卫压平)
if ensure_bom(OUT): # 必须最后一步:前面的中间步骤会整文件重写,BOM 补早了会被冲掉
print('已补 UTF-8 BOM(Drivers/BSP/UI/ 整目录带 BOM 的工程约定,幂等)')
print('OK %d bytes -> %s' % (os.path.getsize(OUT), OUT))
def ensure_bom(path):
"""保证生成物带头 BOM(EF BB BF),且幂等。
为什么要这一步:`Drivers/BSP/UI/` 整目录是工程约定的带 BOM 名单(AGENTS 铁律第 2 条),
目录里其它生成物(如菜单生成器产物)都是带头的,字体是这个目录里唯一会掉队的生成物——
因为本脚本每次都在 :544 调 lv_font_conv **整文件重写**输出,产物天然无 BOM;后面几步虽然
各自读 has_bom 再原样回写,但那是"读到的已经是没有 BOM 的那份",于是 `has_bom` 恒为 False,
"保留原样"压根无从发生(手动补的 BOM 下一轮就被覆盖掉)。
为什么不改成"让每步都保留":真正决定这里要不要 BOM 的是**工程约定**,不是上游产物,所以
收敛在末尾一步显式补,比在 6 个中间步骤里各自维持一个 has_bom 便宜得多,也不依赖调用顺序
(本次踩的坑正是"装配顺序把事实冲掉了")。
幂等:已有 BOM 直接返回,不重复加。只碰最前面 3 字节,字体字节/字形数/glyph_id 全不受影响。
"""
with open(path, 'rb') as fp:
raw = fp.read()
if raw.startswith(b'\xef\xbb\xbf'):
return False
with open(path, 'wb') as fp:
fp.write(b'\xef\xbb\xbf' + raw)
return True
if __name__ == '__main__':
main()