增加监控导出说明文档参数audit#11
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new audit tool readme_flag_audit.py and its corresponding unit tests to verify that CLI flags in the codebase match those documented in the README.md. The review feedback identifies a bug in the regular expression used to parse flags from the README, which incorrectly matches hyphenated words (e.g., mx-exporter as -exporter) and causes false positives. It is recommended to update the regex to avoid these false positives and to add test cases covering hyphenated words to prevent regressions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| from pathlib import Path | ||
|
|
||
|
|
||
| FLAG_RE = re.compile(r"-{1,2}[A-Za-z0-9-]+") |
There was a problem hiding this comment.
当前的正则表达式 -{1,2}[A-Za-z0-9-]+ 会匹配任何包含连字符的单词的后半部分。例如,在 README.md 中存在的 mx-exporter 会被匹配出 -exporter,pod-resources 会被匹配出 -resources,default-counters 会被匹配出 -counters。这会导致 flags_only_in_readme 中包含大量错误的“仅在 README 中存在的参数”假阳性结果。\n\n建议将正则表达式修改为仅匹配以空格开头或位于行首的命令行参数,例如使用非捕获分组 (?:^|\\s) 结合捕获分组来精确提取参数。
| FLAG_RE = re.compile(r"-{1,2}[A-Za-z0-9-]+") | |
| FLAG_RE = re.compile(r"(?:^|\s)(-{1,2}[A-Za-z0-9-]+)") |
| (root / "README.md").write_text("python3 -m mx_exporter -p 8000\n", encoding="utf-8") | ||
|
|
||
| report = build(root) | ||
|
|
||
| self.assertIn("--interval", report["flags_missing_from_readme"]) |
There was a problem hiding this comment.
为了防止未来引入类似的回归问题,建议在测试中加入包含连字符单词(如 mx-exporter)的场景,并断言这些单词不会被错误地识别为命令行参数。
(root / "README.md").write_text("python3 -m mx-exporter -p 8000\n", encoding="utf-8")\n\n report = build(root)\n\n self.assertIn("--interval", report["flags_missing_from_readme"])\n self.assertNotIn("-exporter", report["flags_only_in_readme"])
这次改动补上了监控导出说明文档参数audit,主要是为了解决监控导出与部署排查流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。