[需求] 优化CLA的协议更新比对文件-的开发实现-app-cla-server部分#506
Open
fly333sky wants to merge 1 commit into
Open
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Welcome To opensourceways CommunityHey @fly333sky , thanks for your contribution to the community. Bot Usage ManualI'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. Contact GuideIf you have any questions, please contact the SIG: infratructure , |
CLA Signature Passfly333sky, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
|
|||||||||||||||
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
背景
[需求] 优化CLA的协议更新比对文件(app-cla-server)· 开发流水线 · 开发预览阶段(代码已推 + 预览已部署 + UT 已补;门禁/对抗由 PR CI 异步跑)
改动内容
feat(app-cla-server): 优化 CLA 协议比对,忽略空格/全半角标点/换行等排版噪声
改动概览
按 issue #1482 与 design.md,在
app-cla-server/util/generate_diff.py的 PDF 比对链路中新增「文本归一化」前置环节并重写 token 切分,使比对文件只标记实质性文字增删改,
忽略 PDF 排版噪声(空格、全/半角标点、换行/换页)。命令行入参(3 个位置参数)与
HTML 输出契约(
<pre>+span.removed/span.added)保持不变,Go 调用方(
signing/watch/cla_updated.go)、对外接口、Dockerfile、WebUI 均零改动。改了哪些文件(均在子仓 app-cla-server 内)
util/generate_diff.py(核心改动)normalize(text):unicodedata.normalize('NFKC')+ CJK 标点全/半角映射表re.sub(r'\s+', ' ', text)合并所有空白(含换行/换页)为单空格。,;:()!?~[]等 FFxx 区)。。→. 、→, 【→[ 】→] “→" ”→" ‘→' ’→'。《》→<>:<>经 WebUIv-html会被当成 HTML 标签导致内容从页面消失,直接违反验收标准 Dev #5「标记位置准确可读」;而两份 PDF 同用《》时本就相等、无需
映射,混合用法极罕见,故保留《》原样(风险/收益更优,已在注释/此处说明)。
split_into_words(text):re.findall(r'\w+|[^\w\s]', text),只产出「词 + 单个有意义标点」token,不再产出纯空白 token(杜绝空格类误标,同时保留真实标点增删可被标记)。
compare_texts(text1, text2):入口对两份文本各调一次normalize后再走原有行级+词级比对。compare_pdfs(...):比对后若结果不含任何[-/{+标记(即无实质差异),写出0 字节空文件并返回(WebUI 侧
res.data===""→ 比对卡片隐藏=「无实质改动」,且空文件已存在可避免
service.go/cla_updated.go的重试风暴);关键步骤补充print日志。generate_word_level_diff/save_diff_report/save_diff_report1:保持现状(输出符号
[-...-]/{+...+}与 HTML span 替换逻辑不变)。util/test_generate_diff.py(新增,pytest,27 个用例)normalize:全/半角标点映射、空白/换行/制表符合并、全角数字、幂等、空串、CJK 内容保留。split_into_words:无空白 token、纯空白/空串、纯标点、CJK 词 token。generate_word_level_diff四分支:equal/insert/delete/replace 全覆盖。compare_texts:仅格式差异无标记、实质修改有标记、空输入。testdata/same_text_relayout_*与testdata/only_format_diff_*同文异排版(全/半角标点 + 多空格 + 换行/换页)→ 输出 0 字节空文件,
removed/added计数=0。testdata/real_edits_*含 5 处真实词增删改 → 输出 HTML 含removed/addedspan 各 5,5 处人工标注全部命中(召回率 100%)。IsFileNotExist短路、防重试风暴)。__main__3 个位置参数写产物、参数个数不符sys.exit(1)。save_diff_report:[-...-]/{+...+}→ span 包裹、<pre>外壳。util/testdata/(新增固定样本 PDF + 生成器)same_text_relayout_v1.pdf/same_text_relayout_v2.pdf:同文字、仅全/半角标点+空格+换行差异。only_format_diff_v1.pdf/only_format_diff_v2.pdf:同文字、仅换页/换行/全角标点差异。real_edits_v1.pdf/real_edits_v2.pdf:5 处真实修改(授予→授权给、签署→签订、法院→仲裁机构、免费→无偿、不可转让→可以转让)。
gen_fixtures.py:dev-only 固定样本生成器(仅用 reportlab 生成产物,不是运行时依赖;服务运行时只依赖已锁定的
pypdf@3.12.0,未改 Dockerfile)。testdata 仅用于测试,Dockerfile 仍只 COPY
generate_diff.py,不进生产镜像。对应需求功能点 / 验收标准
normalize+实质 token 比对;IT1 验证→0 字节空文件相关 Issue
resolve https://github.com/opensourceways/backlog/issues/1482
AI 使用声明
当前 PR 是否有 AI 参与:
/ai-develop-preview