Skip to content

refactor: restructure validator with git package extraction and execution unit abstraction#38

Merged
ikjeong merged 9 commits intomainfrom
refactor/validate
Dec 9, 2025
Merged

refactor: restructure validator with git package extraction and execution unit abstraction#38
ikjeong merged 9 commits intomainfrom
refactor/validate

Conversation

@ikjeong
Copy link
Contributor

@ikjeong ikjeong commented Dec 8, 2025

Summary

  • validator 패키지의 책임을 분리하여 git 관련 기능을 독립 패키지로 추출
  • 검증 실행 전략을 추상화하여 linter와 LLM 검증을 통합 인터페이스(executionUnit)로 관리
  • roles 패키지의 공개 API를 최소화하고 사용자명 기반에서 역할 기반 권한 검증으로 일원화
  • 불필요한 공개 타입/함수 제거로 패키지 캡슐화 강화

Changes

Git 패키지 추출

  • internal/validator/git.gointernal/git/changes.go로 이동
  • GitChangegit.Change로 타입 이름 변경
  • GetGitChanges()git.GetChanges()로 함수 이동
  • GetStagedChanges(), ExtractAddedLines() 함수 이동
  • 관련 테스트 파일도 internal/git/changes_test.go로 이동

Execution Unit 추상화 도입

  • internal/validator/execution_unit.go 신규 생성 (271 lines)
  • executionUnit 인터페이스 정의: Execute(), GetRuleIDs(), GetEngineName(), GetFiles()
  • linterExecutionUnit: 동일 linter의 모든 규칙을 배치로 실행
  • llmExecutionUnit: 단일 (파일, 규칙) 쌍을 LLM으로 검증

Validator API 정리

  • LLMValidatorllmValidator로 비공개화 (내부 구현 상세)
  • NewLLMValidator()newLLMValidator()로 비공개화
  • CheckRule()checkRule()로 비공개화
  • internal/validator/selector.go 삭제 (263 lines) - execution unit으로 대체
  • validator.go 리팩토링: 4단계 검증 파이프라인 (RBAC → 규칙 그룹화 → 실행 단위 생성 → 병렬 실행)

Roles 패키지 API 정리

  • ValidateFilePermissions(username, files) 삭제 → ValidateFilePermissionsForRole(role, files) 사용
  • GetUserPolicyPath()getUserPolicyPath()로 비공개화
  • CurrentRoleExists() 삭제

소비자 코드 업데이트

  • internal/cmd/validate.go: git.Change, git.GetChanges() 사용
  • internal/mcp/server.go: git.GetChanges() 호출로 변경

테스트 업데이트

  • E2E 테스트 4개 파일: 새 Validator API 적용 (NewValidator + SetLLMProvider + ValidateChanges)
  • Integration 테스트 7개 파일: validator.GitChangegit.Change 타입 참조 변경
  • RBAC 테스트: 사용자명 기반 → 역할 기반 검증으로 변경

기타

  • internal/linter/pylint/converter.go: 문자열 옵션 래핑 지침 프롬프트 추가
  • 패키지 README 문서 업데이트 (git, validator, roles)

@ikjeong ikjeong self-assigned this Dec 8, 2025
- getEngineName, getDefaultConcurrency, getLanguageFromFile
- parseJSON, parseValidationResponseFallback
- filterChangesForRule, filterLLMRules
- execution unit getters
- findPolicyRule, mapViolationsToRules
- groupRulesByEngine
- llmValidator.validator field (unused)
- llmValidator.Validate() method (never called)
- unused imports (runtime, sync)
- GetRepoInfo() (never used)
- IsGitRepo() (never used)
@ikjeong ikjeong merged commit 3a0e11b into main Dec 9, 2025
1 check passed
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