Skip to content

fix(#40): 초기 셋팅 시 리포지토리 clone 없이 worktree 검증하는 버그 수정#41

Merged
wlgns5376 merged 5 commits into
1.0.4-devfrom
issue-40
Oct 10, 2025
Merged

fix(#40): 초기 셋팅 시 리포지토리 clone 없이 worktree 검증하는 버그 수정#41
wlgns5376 merged 5 commits into
1.0.4-devfrom
issue-40

Conversation

@wlgns5376
Copy link
Copy Markdown
Owner

@wlgns5376 wlgns5376 commented Oct 2, 2025

Summary

초기 셋팅 시 리포지토리가 clone되지 않은 상태에서 worktree 검증이 실패하는 버그를 수정했습니다.

Problem

초기 셋팅 시 repository clone을 먼저 실행해야 하는데 worktree가 존재한다고 체크되어 오류가 발생하는 문제가 있었습니다.

Root Cause

  1. workspace-manager.ts의 isWorktreeValid(): 디렉토리만 존재하면 무조건 true 반환
  2. workspace-setup.ts의 validateEnvironment(): 초기 셋팅 시에도 worktree 검증 시도

이로 인해:

  1. setupWorktree()에서 유효한 worktree로 인식하여 early return
  2. ensureRepository() 호출이 스킵됨
  3. addWorktree() 호출 시 "Repository not found" 오류 발생

Solution

Phase 1: workspace-manager.ts 수정

  • isWorktreeValid() 메서드의 로직 개선
    • 기존: 디렉토리만 존재하면 무조건 true 반환
    • 수정: .git 파일이 존재하고 유효한 gitdir: 참조를 포함할 때만 true 반환
  • 로그 레벨 조정 (INFO → DEBUG)

Phase 2: workspace-setup.ts 수정 (이번 커밋)

  • validateEnvironment() 메서드에서 worktreeCreated 플래그 검증 추가
    • 초기 셋팅 시(worktreeCreated=false): 디렉토리 존재 여부만 확인, worktree 검증 건너뜀
    • worktree 생성 후(worktreeCreated=true): Git worktree 유효성 검증 수행

Changes

  1. src/services/worker/workspace-setup.ts

    • validateEnvironment() 메서드에 worktreeCreated 플래그 검증 로직 추가
    • 초기 셋팅 시 worktree 검증 건너뛰기 로직 추가
  2. src/services/manager/workspace-manager.ts

    • isWorktreeValid() 메서드의 검증 로직 개선
    • .git 파일의 gitdir: 참조 검증 추가
  3. tests/unit/services/worker/workspace-setup.test.ts

    • 초기 셋팅 시나리오 테스트 케이스 2개 추가
    • worktreeCreated 플래그에 따른 검증 로직 테스트

Test Results

  • ✅ workspace-setup 관련 테스트 13개 모두 통과
  • ✅ 빌드 성공
  • ✅ 타입 에러 없음

Test Plan

  • 코드 빌드 성공 확인
  • workspace-setup 단위 테스트 통과 확인
  • 초기 셋팅 시 리포지토리 clone 정상 동작 확인
  • worktree 생성 정상 동작 확인

Closes #40

🤖 Generated with Claude Code

wlgns5376 and others added 4 commits October 2, 2025 17:10
- isWorktreeValid() 메서드가 디렉토리만 존재하면 항상 true를 반환하던 문제 수정
- .git 파일이 존재하고 유효한 gitdir 참조를 포함할 때만 true 반환하도록 변경
- 초기 셋팅 시 리포지토리가 clone되지 않았을 때 발생하던 오류 해결

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

Co-Authored-By: Claude <noreply@anthropic.com>
- validateEnvironment()에서 worktree가 유효하지 않으면 false를 반환하도록 수정
- 기존에는 worktree 검증 실패 시에도 true를 반환하여 초기 셋팅 시 오류 발생
- workspace-manager.test.ts에 BUG #40 재현 테스트 추가
- workspace-setup.test.ts에 worktree 검증 실패 시 테스트 추가

Related: #40

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

Co-Authored-By: Claude <noreply@anthropic.com>
초기 셋팅 시 repository clone이 아직 이루어지지 않았는데 worktree 검증을
시도하는 문제를 수정했습니다.

주요 변경 사항:
- workspace-setup.ts의 validateEnvironment() 메서드에서 worktreeCreated
  플래그를 확인하여 초기 셋팅 시 worktree 검증을 건너뜀
- worktreeCreated가 false일 때는 디렉토리 존재 여부만 확인
- worktreeCreated가 true일 때만 Git worktree 유효성 검증 수행
- 초기 셋팅 시나리오를 위한 테스트 케이스 추가

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

Co-Authored-By: Claude <noreply@anthropic.com>
초기 셋팅 시 리포지토리 clone 버그는 이전 커밋들(a82ca33, 89420bc, 9f42f0d)에서
이미 수정되었으나, 통합 테스트에서 잘못된 기대값으로 인해 실패하고 있었습니다.

주요 변경 사항:
- TaskAssignmentValidator 테스트: 디렉토리만 있고 .git 파일이 없으면
  isWorktreeValid()가 false를 반환해야 함 (기존: true 기대)
- canAssignIdleWorkerToTask 테스트: 유효한 worktree를 위해 .git 파일 생성 추가
- 우선순위 시스템 테스트: 유효한 worktree를 위해 .git 파일 생성 추가

테스트 결과:
- workspace 관련 테스트 50개 모두 통과
- 버그 수정 검증 완료

Closes #40

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

Co-Authored-By: Claude <noreply@anthropic.com>
Repository owner deleted a comment from wlgns5376 Oct 9, 2025
@woody-kang
Copy link
Copy Markdown
Collaborator

아래 에러가 발생하는데 원인을 분석해주고 관련된 테스트 코드가 있는지 검토하고 있다면 왜 이 에러를 감지하지 못했는지 검토해줘

2025-10-09T02:39:01.769Z [ERROR] Failed to ensure repository {
  "error": {
    "message": "Failed to clone repository: Git command failed with code 128: Cloning into '\"workspace/repositories/wlgns5376_ai-devteam-test\"'...\nfatal: protocol '\"https' is not supported\n",
    "code": "REPOSITORY_ENSURE_ERROR",
    "timestamp": "2025-10-09T02:39:01.769Z",
    "context": {
      "repositoryId": "wlgns5376/ai-devteam-test",
      "error": {
        "name": "Error",
        "message": "Failed to clone repository: Git command failed with code 128: Cloning into '\"workspace/repositories/wlgns5376_ai-devteam-test\"'...\nfatal: protocol '\"https' is not supported\n",
        "stack": "Error: Failed to clone repository: Git command failed with code 128: Cloning into '\"workspace/repositories/wlgns5376_ai-devteam-test\"'...\nfatal: protocol '\"https' is not supported\n\n    at /app/dist/services/git/git.service.js:234:23\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async GitLockService.withLock (/app/dist/services/git/git-lock.service.js:62:20)\n    at async RepositoryManager.cloneRepository (/app/dist/services/manager/repository-manager.js:88:13)\n    at async RepositoryManager.ensureRepository (/app/dist/services/manager/repository-manager.js:69:20)\n    at async WorkspaceManager.setupWorktree (/app/dist/services/manager/workspace-manager.js:91:36)\n    at async WorkspaceSetup.prepareWorkspace (/app/dist/services/worker/workspace-setup.js:42:13)\n    at async Worker.startExecution (/app/dist/services/worker/worker.js:150:35)"
      }
    }
  }
}

## 문제
- Git clone 실행 시 `protocol '"https' is not supported` 에러 발생
- safeExec 메서드가 명령어를 split(' ')로 파싱하면서 따옴표가 인자에 포함됨
- spawn에 전달될 때 따옴표가 제거되지 않아 Git이 프로토콜을 인식하지 못함

## 해결
- parseCommand() 메서드 추가: 따옴표를 고려한 명령어 파싱
- 따옴표 안의 공백을 구분자로 인식하지 않도록 처리
- URL, 경로 등에 공백이나 특수문자가 있어도 올바르게 처리

## 테스트
- 따옴표가 포함된 URL 파싱 테스트 추가
- 공백이 포함된 경로 파싱 테스트 추가
- 여러 인자가 있는 명령어 파싱 테스트 추가
- 총 9개 테스트 모두 통과

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

Co-Authored-By: Claude <noreply@anthropic.com>
@wlgns5376
Copy link
Copy Markdown
Owner Author

@woody-kang 리뷰 피드백이 반영되었습니다.

문제 원인

git clone 명령 실행 시 protocol '"https' is not supported 에러가 발생했습니다.

근본 원인: safeExec 메서드가 명령어를 split(' ')로 파싱하면서 따옴표가 인자의 일부로 포함되어, spawn에 전달될 때 Git이 "https를 프로토콜로 인식하여 에러가 발생했습니다.

해결 방법

  1. parseCommand() 메서드 추가: 따옴표를 고려한 명령어 파싱 로직 구현
  2. 따옴표 안의 공백을 구분자로 인식하지 않도록 처리
  3. URL, 경로 등에 공백이나 특수문자가 있어도 올바르게 처리

테스트 보완

기존 테스트는 정상적인 URL만 테스트했고, 따옴표가 포함된 인자 처리를 검증하지 않았습니다.

추가된 테스트:

  • 따옴표가 포함된 URL 파싱 테스트
  • 공백이 포함된 경로 파싱 테스트
  • 여러 인자가 있는 명령어 파싱 테스트

모든 테스트(총 9개) 통과했습니다.

재검토 부탁드립니다.

@wlgns5376 wlgns5376 merged commit 3e5c501 into 1.0.4-dev Oct 10, 2025
2 checks passed
@wlgns5376 wlgns5376 deleted the issue-40 branch October 10, 2025 01:00
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.

2 participants