diff --git a/dwg_review/annotator.py b/dwg_review/annotator.py index 8364f43..b13e644 100644 --- a/dwg_review/annotator.py +++ b/dwg_review/annotator.py @@ -36,11 +36,13 @@ def annotate(ctx, issues, *, dry_run=False, log=print): """按问题列表回写批注,返回 (created, highlighted) 两个 handle 列表。""" created = [] highlighted = [] + seen = set() # 同一 handle 只处理一次,避免重复批注 for issue in issues: handle = issue.get("handle") - if not handle: + if not handle or handle in seen: continue + seen.add(handle) text = f"[{issue.get('severity', '?')}] {issue.get('message', '')}" @@ -81,8 +83,6 @@ def annotate(ctx, issues, *, dry_run=False, log=print): continue # 引线建好后再高亮原实体(失败不影响已创建的批注) - if handle in highlighted: - continue try: ctx.tools.call("highlight_entities", {"handle": handle, "color": 1}) highlighted.append(handle) diff --git a/test_screenshot.png b/test_screenshot.png deleted file mode 100644 index fefc0ba..0000000 Binary files a/test_screenshot.png and /dev/null differ diff --git a/tests/test_annotator.py b/tests/test_annotator.py index 46dbe3a..c16c3c9 100644 --- a/tests/test_annotator.py +++ b/tests/test_annotator.py @@ -120,8 +120,8 @@ def test_annotate_handles_multiple_created_entities(): assert created == ["N1", "N2"] -def test_annotate_created_not_deduped_known_gap(): - """已知瑕疵:同一 handle 出现两次会创建两条批注(created 无去重,仅 highlighted 去重)。""" +def test_annotate_dedupes_repeated_handle(): + """同一 handle 出现两次只批注一次(created 与 highlighted 均去重)。""" ctx = make_ctx(client=build_client()) created, highlighted = annotate( ctx, @@ -131,8 +131,9 @@ def test_annotate_created_not_deduped_known_gap(): ], log=lambda *a: None, ) - assert created == ["NEW1", "NEW1"] # 重复批注(期望去重) - assert highlighted == ["A"] # 高亮已去重 + assert created == ["NEW1"] + assert highlighted == ["A"] + assert len(ctx.client.called("add_leader_annotation")) == 1 def test_annotate_propagates_protocol_error_on_detail():