Stage 7: tools.py 패키지화 + @tool 레지스트리 + 휴면 삭제 (2259→1532줄, cov 88%)#32
Merged
Conversation
- 파일 역할 반전: 실체는 __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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
프로그램 Stage 7/9 (R9). god-file tools.py의 이중 레지스트리 lockstep과 40% 휴면 코드 제거.
변경
opencrab/mcp/tools/패키지. 실체는 init.py(모듈명 == opencrab.mcp.tools), _legacy/_context는 재export shim@tool(name, schema)로 전환 — 기존 TOOL_SCHEMAS/_TOOL_FUNCTIONS/def 3중 lockstep 편집을 데코레이터 1곳으로._registry.py의 ToolSpec + _REGISTRY가 TOOLS/dispatch 구동(WRITE_TOOLS 락·에러 envelope 보존)_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보류 (후속 과제)
물리적 5-모듈 분할은
mock.patch("opencrab.mcp.tools.X")가 핸들러의 물리 정의 위치와 강결합돼(패치는 정의 모듈 __dict__만 덮음) 30+ 테스트를 깨므로 보류 — 테스트 mock 전략 재설계 동반 필요. 이번엔 god-file의 실제 고통(lockstep·휴면)만 해소._context.py서브모듈명 충돌도 후속 리네임 권고.원장
fable 검증 PASS
TOOLS main 바이트-동일 전수 증명, 휴면 20개 라이브 호출자 0, import 계약 전건·스모크, _registry 수정 타당, dispatch e2e 동일. 시뮬레이션-CI 1660/0 failed.