Skip to content

Conversation

@jk-kim0
Copy link
Contributor

@jk-kim0 jk-kim0 commented Feb 11, 2026

Summary

reverse_sync_cli.py(1,271줄)에 핵심 알고리즘 4개가 밀집되어 테스트·디버깅이 어려운 문제를 해결합니다.
4개 모듈로 분리하여 단위 테스트 가능성을 확보하고, 후속 작업(정규화 테스트 매트릭스, 매칭 실패 로깅)의 기반을 마련합니다.

  • text_normalizer.py (70줄): normalize_mdx_to_plain, collapse_ws, strip_list_marker, EMOJI_RE, INVISIBLE_RE 추출
  • text_transfer.py (78줄): align_chars, find_insert_pos, transfer_text_changes 추출
  • block_matcher.py (137줄): find_mapping_by_text, find_containing_mapping 추출
  • patch_builder.py (296줄): build_patches, build_list_item_patches, table/list 헬퍼 함수 추출
  • reverse_sync_cli.py에서 추출된 함수 제거 및 import 교체 (1,271→714줄)
  • 테스트 import 경로를 새 모듈의 public API로 업데이트 (test_reverse_sync_cli.py, test_reverse_sync_e2e.py)

의존성 방향 (비순환)

patch_builder → block_matcher → text_normalizer
                text_transfer (독립)

네이밍 변경

모듈 간 공개 API는 _ prefix를 제거합니다 (예: _normalize_mdx_to_plainnormalize_mdx_to_plain).

Test plan

  • 단위 테스트 전체 통과 (PYTHONPATH=bin python -m pytest tests/ -v — 202 passed)
  • Shell e2e 테스트 16/16 통과 (cd tests && make test-reverse-sync)

Related tickets & links

  • skills-jk#99 (Phase 1 회고)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 [email protected]

## Summary
reverse_sync_cli.py(1,271줄)에 밀집된 핵심 알고리즘을 4개 모듈로 분리하여
단위 테스트 가능성을 확보하고 후속 작업의 기반을 마련합니다.

- `text_normalizer.py`: MDX→plain text 정규화 함수 추출 (70줄)
- `text_transfer.py`: 텍스트 변경 전이 함수 추출 (78줄)
- `block_matcher.py`: XHTML 매핑 매칭 함수 추출 (137줄)
- `patch_builder.py`: XHTML 패치 빌드 함수 추출 (296줄)
- `reverse_sync_cli.py`에서 추출된 함수 제거 및 import 교체 (1,271→714줄)
- 테스트 import 경로를 새 모듈로 업데이트

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vercel
Copy link

vercel bot commented Feb 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
querypie-docs Canceled Canceled Comment Feb 11, 2026 9:25am

Request Review

## Summary
test_reverse_sync_e2e.py에서 `_build_patches` import를 새 모듈 경로로 업데이트합니다.

- `reverse_sync_cli._build_patches` → `reverse_sync.patch_builder.build_patches`

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jk-kim0 jk-kim0 self-assigned this Feb 11, 2026
@jk-kim0 jk-kim0 merged commit 9f6933f into main Feb 11, 2026
5 of 7 checks passed
@jk-kim0 jk-kim0 deleted the jk/refactor-reverse-sync-cli branch February 11, 2026 09:24
jk-kim0 added a commit that referenced this pull request Feb 12, 2026
## Summary
- `bin/reverse_sync/sidecar_lookup.py` 모듈 신규 추가 — mapping.yaml 로드, 인덱스
구축, 2-hop 조회
- `tests/test_sidecar_lookup.py` 유닛 테스트 38개 추가

### Background
#682에서 forward converter가 `var/<page_id>/mapping.yaml` sidecar 파일을 생성하도록
구현 완료.
이 모듈은 해당 sidecar 파일을 로드하고 인덱스를 구축하여,
reverse-sync pipeline에서 기존 7단계 fuzzy text matching을 O(1) 직접 조회로 교체할 수 있는
기반 모듈입니다.

### 이 PR의 범위
- **포함**: `sidecar_lookup.py` 모듈 + 유닛 테스트만
- **미포함**: reverse-sync pipeline (`reverse_sync_cli.py`,
`patch_builder.py`)에 실제 적용은 후속 PR에서 진행

### 주요 함수
| 함수 | 설명 |
|---|---|
| `load_sidecar_mapping()` | mapping.yaml → `List[SidecarEntry]` |
| `build_mdx_to_sidecar_index()` | MDX block index → SidecarEntry 역인덱스 |
| `build_xpath_to_mapping()` | xhtml_xpath → BlockMapping 인덱스 |
| `find_mapping_by_sidecar()` | 2-hop 조회: MDX index → SidecarEntry →
BlockMapping |
| `generate_sidecar_mapping()` | XHTML + MDX → mapping.yaml 생성 (테스트용) |

## Test plan
- [x] 38개 유닛 테스트 통과 (pytest)
- [x] 기존 202개 테스트 regression 없음 (240/240 전체 통과)
- [x] 16/16 shell 통합 테스트 통과

## Related tickets & links
- #682 (forward converter sidecar 생성)
- #679 (reverse_sync_cli 모듈 분리)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant