fix: 避免空 Description 模板触发误报冲突
Deploy production / deploy (push) Successful in 49s

This commit is contained in:
yuxuanhui
2026-09-10 16:36:35 +08:00
parent 49bf8de9c8
commit f25161d624
2 changed files with 77 additions and 3 deletions
+22 -2
View File
@@ -72,8 +72,25 @@ def source(raw):
}
def comparable_description(text):
"""Canonicalize empty platform placeholders only; preserve all substantive text.
This comparison key must never replace the reviewed text sent to the platform.
Unknown or partially filled templates remain exact to protect concurrent edits.
"""
empty_template = r"\s*" + r"\s*".join(re.escape(heading.strip()) for heading in HEADINGS) + r"\s*"
return "" if not text.strip() or re.fullmatch(empty_template, text) else text
def fingerprint(value):
return hashlib.sha256(json.dumps(value, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
comparable = {
**value,
"sections": {
key: {**item, "description": comparable_description(item["description"])}
for key, item in value["sections"].items()
},
}
return hashlib.sha256(json.dumps(comparable, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
def parse_description(text):
@@ -300,7 +317,10 @@ async def run_check(runner, job_id, payload):
patch = {}
for section, item in current["sections"].items():
before, target = expected["sections"][section], payload["descriptions"][section]
if item["code"] != before["code"] or item["description"] not in (before["description"], target):
if item["code"] != before["code"] or comparable_description(item["description"]) not in (
comparable_description(before["description"]),
comparable_description(target),
):
raise WqError("平台表达式或 Description 已变化,未覆盖;请刷新后重新核对", "conflict")
if item["description"] != target:
patch[section] = {"description": target}