Skip to content

feat(reverse-sync): Sidecar mapping lookup 모듈 및 유닛 테스트 추가#685

Merged
jk-kim0 merged 1 commit intomainfrom
feat/sidecar-lookup-in-reverse-sync
Feb 12, 2026
Merged

feat(reverse-sync): Sidecar mapping lookup 모듈 및 유닛 테스트 추가#685
jk-kim0 merged 1 commit intomainfrom
feat/sidecar-lookup-in-reverse-sync

Conversation

@jk-kim0
Copy link
Contributor

@jk-kim0 jk-kim0 commented 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

  • 38개 유닛 테스트 통과 (pytest)
  • 기존 202개 테스트 regression 없음 (240/240 전체 통과)
  • 16/16 shell 통합 테스트 통과

Related tickets & links

🤖 Generated with Claude Code

@jk-kim0 jk-kim0 self-assigned this Feb 12, 2026
@jk-kim0 jk-kim0 force-pushed the feat/sidecar-lookup-in-reverse-sync branch from b81e9fb to 34aff15 Compare February 12, 2026 12:09
@vercel
Copy link

vercel bot commented Feb 12, 2026

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

Project Deployment Actions Updated (UTC)
querypie-docs Canceled Canceled Comment Feb 12, 2026 0:22am

Request Review

## Description
- `bin/reverse_sync/sidecar_lookup.py` 모듈 신규 추가
  - `mapping.yaml` 파일 로드 (`load_sidecar_mapping`)
  - MDX block index → SidecarEntry 역인덱스 구축 (`build_mdx_to_sidecar_index`)
  - xhtml_xpath → BlockMapping 인덱스 구축 (`build_xpath_to_mapping`)
  - 2-hop 조회: MDX index → SidecarEntry → BlockMapping (`find_mapping_by_sidecar`)
  - XHTML + MDX로부터 mapping.yaml 생성 (`generate_sidecar_mapping`)
- `tests/test_sidecar_lookup.py` 유닛 테스트 38개 추가
  - 각 함수별 단위 테스트 + 실제 테스트 케이스 기반 통합 테스트
  - 2-hop 조회 전체 경로 검증

### Background
#682에서 forward converter가 `var/<page_id>/mapping.yaml` sidecar 파일을 생성하도록 구현 완료.
이 모듈은 해당 sidecar 파일을 로드하고 인덱스를 구축하여,
reverse-sync pipeline에서 O(1) 블록 매칭을 가능하게 하는 기반 모듈입니다.
실제 reverse-sync pipeline 적용은 후속 PR에서 진행합니다.

## Added/updated tests?
- [x] Yes — 38개 유닛 테스트 추가 (240/240 전체 통과)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jk-kim0 jk-kim0 force-pushed the feat/sidecar-lookup-in-reverse-sync branch from 34aff15 to 83cb91d Compare February 12, 2026 12:18
@jk-kim0 jk-kim0 changed the title feat(reverse-sync): Sidecar mapping 기반 O(1) 블록 매칭 도입 feat(reverse-sync): Sidecar mapping lookup 모듈 및 유닛 테스트 추가 Feb 12, 2026
@jk-kim0 jk-kim0 marked this pull request as ready for review February 12, 2026 12:20
@jk-kim0 jk-kim0 merged commit 9317633 into main Feb 12, 2026
5 of 7 checks passed
@jk-kim0 jk-kim0 deleted the feat/sidecar-lookup-in-reverse-sync branch February 12, 2026 12:21
jk-kim0 added a commit that referenced this pull request Feb 12, 2026
## Summary
- `sidecar_lookup.py` 코드 리뷰에서 발견된 이슈 수정
- 미사용 코드 제거, 방어 코드 추가, 테스트 파일명 규칙 준수

## Changes
| 항목 | 변경 |
|---|---|
| `load_sidecar_mapping()` | 빈 YAML 파일 방어 (`yaml.safe_load() or {}`) |
| `generate_sidecar_mapping()` | 미사용 `SKIP_TYPES`, `NO_MDX_XPATHS` 제거 |
| `_count_child_mdx_blocks()` | 미사용 파라미터 4개 제거 |
| 테스트 파일 | `test_sidecar_lookup.py` →
`test_reverse_sync_sidecar_lookup.py` |
| 테스트 import | 미사용 `unittest.mock.patch` 제거 |
| 테스트 추가 | 빈 YAML 파일 edge case |

## Test plan
- [x] 241/241 pytest 통과
- [x] 기존 동작 변경 없음

## Related tickets & links
- #685 (원본 PR)

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

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
jk-kim0 added a commit that referenced this pull request Feb 12, 2026
## Description
- `build_patches()`에 sidecar 직접 조회(O(1))를 primary 매칭으로 추가합니다.
- Sidecar로 parent mapping을 찾은 후, child 해석을 통해 개별 자식 매핑으로 정확히 대응합니다.
- Child 해석 실패 시 (list/table 블록 등) 기존 fuzzy matching으로 자연스럽게 fallback합니다.
- `run_verify()`에서 `generate_sidecar_mapping()`으로 on-the-fly sidecar를 생성하여 `build_patches()`에 전달합니다.

### 매칭 흐름
1. Phase 1: Sidecar 직접 조회 → parent일 경우 child 해석 (4단계: 완전 일치, 공백 무시, 리스트 마커 제거)
2. Phase 2: Fuzzy matching fallback (`find_mapping_by_text()`)
3. Phase 3: Sub-block 분리 매칭 (list item, table row, containing mapping)

### 기존 동작과의 호환성
- `mdx_to_sidecar`, `xpath_to_mapping` 파라미터는 Optional (None이면 기존 fuzzy matching만 사용)
- 기존 `build_patches()` 호출부는 변경 없이 동작

## Related tickets & links
- #685, #687 (sidecar_lookup.py 모듈)

## Added/updated tests?
- [x] No, and this is why: 기존 241개 pytest + 16개 reverse-sync 통합 테스트가 모두 통과하여 회귀 없음 확인

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jk-kim0 added a commit that referenced this pull request Feb 12, 2026
## Summary
- `block_matcher.py` 삭제 (138줄) — `find_mapping_by_text()`,
`find_containing_mapping()` 제거
- `build_patches()` 매칭을 3단계(sidecar → fuzzy → sub-block)에서 **1단계(sidecar
O(1) 조회)** 로 간소화
- Child 해석 실패 시 fuzzy fallback 대신 **parent mapping을 containing block으로
직접 사용**
- `build_list_item_patches()`, `build_table_row_patches()`도 sidecar 기반으로
전환

### 매칭 흐름 (변경 후)
```
BlockChange(index=N)
  → Sidecar 직접 조회 (O(1))
    → children 있으면: child 해석 시도 (collapse_ws → 공백무시 → 리스트마커제거)
      → 성공: child xpath로 patch
      → 실패: parent를 containing block으로 사용
    → children 없으면: 직접 patch
  → Sidecar에 없으면:
    → list 블록: build_list_item_patches (sidecar parent → child 해석)
    → markdown table: build_table_row_patches (sidecar parent → containing)
    → 그 외: skip
```

### 변경 파일
| 파일 | 변경 |
|------|------|
| `patch_builder.py` | signature 필수화, 메인 루프 재작성, sub-함수 sidecar 전환 |
| `block_matcher.py` | **삭제** (-138줄) |
| `test_reverse_sync_cli.py` | fuzzy 테스트 2개 삭제, sidecar 파라미터 추가, **신규 5개
테스트** |
| `test_reverse_sync_e2e.py` | sidecar 생성 추가 |

### 전체 LOC 변화
- 삭제: 244줄 (block_matcher.py + fuzzy 분기 + fuzzy 테스트)
- 추가: 362줄 (sidecar 분기 + 유닛 테스트 5개)
- 순 증가: +118줄 (테스트 247줄 포함, 프로덕션 코드는 -129줄)

## Test plan
- [x] 244/244 pytest 통과
- [x] 신규 유닛 테스트 5개: child 해석 성공/실패, unmapped skip, list item 매칭/fallback
- [x] reverse-sync batch verify: 139/148 pass (4 fail은 기존 띄어쓰기 전이 이슈, 별도
대응 예정)

## Related
- #685 sidecar_lookup.py 모듈
- #687 sidecar_lookup.py 코드 리뷰 반영

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant