Skip to content

Commit e8aefbe

Browse files
committed
Strip numbering from revised_text when violation_text is stripped
• Track strip mode instead of boolean • Apply same stripping to revised_text • Only strip for replace actions • Add regression test coverage • Ensure consistent numbering handling
1 parent 4915048 commit e8aefbe

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

skills/doc-audit/scripts/docx_edit/item_search_mixin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,15 @@ def _locate_item_match(
513513
match_pos = -1
514514
matched_text = violation_text
515515
matched_override = None
516-
matched_is_stripped = False
516+
matched_strip_mode: Optional[str] = None
517517

518-
for search_text, is_stripped in search_attempts:
518+
for search_text, strip_mode in search_attempts:
519519
match_pos, matched_override = self._find_in_runs_with_normalization(
520520
all_runs, search_text
521521
)
522522
if match_pos != -1:
523523
matched_text = matched_override or search_text
524-
matched_is_stripped = is_stripped
524+
matched_strip_mode = strip_mode
525525
break
526526

527527
if match_pos != -1:
@@ -530,7 +530,12 @@ def _locate_item_match(
530530
matched_start = match_pos
531531
is_cross_paragraph = len(body_paras_data) > 1
532532
violation_text = matched_text
533-
numbering_stripped = matched_is_stripped
533+
numbering_stripped = matched_strip_mode is not None
534+
if matched_strip_mode and item.fix_action == 'replace':
535+
stripped_revised, _ = strip_numbering_by_mode(
536+
revised_text, matched_strip_mode
537+
)
538+
revised_text = stripped_revised
534539

535540
if self.verbose:
536541
if is_cross_paragraph:

tests/test_apply_audit_edits_core.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,60 @@ def test_no_strip_normal(self):
803803
assert strip_auto_numbering("Normal text") == ("Normal text", False)
804804

805805

806+
class TestLocateItemMatchNumbering:
807+
"""Regression tests for numbering stripping during item locate."""
808+
809+
def test_boundary_body_match_strips_revised_text(self):
810+
"""When violation_text is stripped by mode, revised_text should be stripped too."""
811+
applier = create_mock_applier()
812+
para = create_paragraph_xml(
813+
"三防漆涂覆\n依据文件ADYU0.005.000《三防漆涂覆通用工艺规程》和"
814+
"ADYU2.088.1192ZD6《信息处理组件三防漆涂覆作业指导书》中要求执行。",
815+
para_id="AAAA1111",
816+
)
817+
item = create_edit_item(
818+
uuid="AAAA1111",
819+
uuid_end="AAAA1111",
820+
fix_action="replace",
821+
violation_text=(
822+
"h) 三防漆涂覆\n依据文件ADYU0.005.000《三防漆涂覆通用工艺规程》和"
823+
"ADYU2.088.1192ZD6《信息处理组件三防漆涂覆作业指导书》中要求执行。"
824+
),
825+
revised_text=(
826+
"h) 三防漆涂覆\n依据文件ADYU0.005.000《三防漆涂覆通用工艺规程》和"
827+
"ADYU2.088.1192ZD5《信息处理组件三防漆涂覆作业指导书》中要求执行。"
828+
),
829+
)
830+
831+
# Force fallback route:
832+
# single-para original miss -> numbering variant miss -> boundary_crossed ->
833+
# body segment original miss -> body segment numbering variant hit
834+
search_results = iter([(-1, None), (-1, None), (-1, None), (0, None)])
835+
applier._find_in_runs_with_normalization = lambda runs, text: next(search_results)
836+
applier._iter_paragraphs_in_range = lambda start_para, uuid_end: iter([para])
837+
applier._collect_runs_info_across_paragraphs = (
838+
lambda start_para, uuid_end: ([], "", False, "boundary_crossed")
839+
)
840+
applier._find_tables_in_range = lambda start_para, uuid_end: []
841+
applier._is_paragraph_in_table = lambda _para: False
842+
applier._apply_fallback_comment = lambda *args, **kwargs: None
843+
844+
context = applier._locate_item_match(
845+
item=item,
846+
anchor_para=para,
847+
violation_text=item.violation_text,
848+
revised_text=item.revised_text,
849+
)
850+
851+
assert context["target_para"] is para
852+
assert context["matched_start"] == 0
853+
assert context["numbering_stripped"] is True
854+
assert context["violation_text"].startswith("三防漆涂覆")
855+
assert context["revised_text"].startswith("三防漆涂覆")
856+
assert not context["revised_text"].startswith("h) ")
857+
assert "ZD5" in context["revised_text"]
858+
859+
806860
# ============================================================
807861
# Tests: _find_revision_ancestor
808862
# ============================================================

0 commit comments

Comments
 (0)