Skip to content

Stage 7: tools.py 패키지화 + @tool 레지스트리 + 휴면 삭제 (2259→1532줄, cov 88%)#32

Merged
epruseal merged 2 commits into
mainfrom
refactor/s7-tools-pkg
Jul 6, 2026
Merged

Stage 7: tools.py 패키지화 + @tool 레지스트리 + 휴면 삭제 (2259→1532줄, cov 88%)#32
epruseal merged 2 commits into
mainfrom
refactor/s7-tools-pkg

Conversation

@epruseal

@epruseal epruseal commented Jul 6, 2026

Copy link
Copy Markdown
Owner

프로그램 Stage 7/9 (R9). god-file tools.py의 이중 레지스트리 lockstep과 40% 휴면 코드 제거.

변경

  • tools.py(2259줄) → opencrab/mcp/tools/ 패키지. 실체는 init.py(모듈명 == opencrab.mcp.tools), _legacy/_context는 재export shim
  • 이중 레지스트리 제거: 16 라이브 핸들러를 @tool(name, schema)로 전환 — 기존 TOOL_SCHEMAS/_TOOL_FUNCTIONS/def 3중 lockstep 편집을 데코레이터 1곳으로. _registry.py의 ToolSpec + _REGISTRY가 TOOLS/dispatch 구동(WRITE_TOOLS 락·에러 envelope 보존)
  • 휴면 코드 삭제: dispatch 불가능한 미등록 함수 20개(query_bm25·rebac·extract·ingest·workflow·approval·identity 5·canonicalize 2·promotion 4·billing 2) — git 이력 보존, 라이브 호출자 0 확인
  • init.py 2259→1532줄
  • fix: _registry가 _context 서브모듈 import 시 부모 패키지 dict 속성을 덮어쓰던 잠복 버그 → 패키지 자체에서 import

프로덕션 안전 (Risk #1: 2-instance serve + apps.api.main)

  • from opencrab.mcp.tools import TOOLS, dispatch_tool, UnknownToolError 등 전 import 경로 무손상, apps.api.main 스모크 green
  • TOOLS가 main과 바이트 단위 동일(16개 이름·순서·스키마 전수 대조), dispatch end-to-end 출력 동일

보류 (후속 과제)

물리적 5-모듈 분할은 mock.patch("opencrab.mcp.tools.X")가 핸들러의 물리 정의 위치와 강결합돼(패치는 정의 모듈 __dict__만 덮음) 30+ 테스트를 깨므로 보류 — 테스트 mock 전략 재설계 동반 필요. 이번엔 god-file의 실제 고통(lockstep·휴면)만 해소. _context.py 서브모듈명 충돌도 후속 리네임 권고.

원장

시점 passed skipped cov
Stage 6b 1635 3 86%
Stage 7 1660 3 ~88% (래칫 82)

fable 검증 PASS

TOOLS main 바이트-동일 전수 증명, 휴면 20개 라이브 호출자 0, import 계약 전건·스모크, _registry 수정 타당, dispatch e2e 동일. 시뮬레이션-CI 1660/0 failed.

epruseal added 2 commits July 6, 2026 09:15
- 파일 역할 반전: 실체는 __init__.py(모듈명 == opencrab.mcp.tools, patch 타겟 보존), _legacy/_context는 재export shim
- mock.patch('opencrab.mcp.tools.X')가 핸들러 물리 위치와 강결합 — 실증 후 이 설계 채택(import·patch 경로 무손상)
- _registry.py: ToolSpec+@tool 데코레이터(중복 등록 ValueError)+UnknownToolError+dispatch(WRITE_TOOLS 락 보존), 아직 미배선
- test_tool_registry_contract 25건: TOOLS 이름+순서 골든 스냅샷(마이그레이션 전 구간 green 유지)
- 동작·TOOLS·import 전부 불변, apps.api.main 스모크 green
- 16 라이브 핸들러를 @tool(name, schema)로 전환 — TOOL_SCHEMAS/_TOOL_FUNCTIONS lockstep 3중 편집 제거, 스키마를 함수 옆으로
- 등록 순서=TOOLS 골든 스냅샷 순서 정확 일치(파일 내 재배치), 백컴팟 TOOL_SCHEMAS/_TOOL_FUNCTIONS/dispatch/UnknownToolError 유지
- 휴면 미등록 함수 20개(query_bm25·rebac·extract·ingest·workflow·approval·identity 5·canonicalize 2·promotion 4·billing 2) 삭제 — git 이력 보존, 테스트는 KeyError 계약만 유지
- fix: _registry가 _context 서브모듈 import 시 부모 패키지 속성 덮어쓰던 잠복 버그 → 패키지 자체에서 import
- 물리적 5-모듈 분할은 mock.patch('opencrab.mcp.tools.X')의 정의위치 강결합 때문에 보류(후속 과제)
- 커버리지 86→87.8%, apps.api.main 스모크 green
@epruseal
epruseal merged commit 7289ce1 into main Jul 6, 2026
1 check passed
@epruseal
epruseal deleted the refactor/s7-tools-pkg branch July 6, 2026 00:43
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