Skip to content

Commit a82ca33

Browse files
wlgns5376claude
andcommitted
fix(#40): worktreeCreated 플래그 검증으로 초기 셋팅 시 worktree 검증 건너뛰기
초기 셋팅 시 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>
1 parent 89420bc commit a82ca33

2 files changed

Lines changed: 77 additions & 14 deletions

File tree

src/services/worker/workspace-setup.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class WorkspaceSetup implements WorkspaceSetupInterface {
9898
try {
9999
// 기본 디렉토리 존재 확인
100100
await fs.access(workspaceInfo.workspaceDir);
101-
101+
102102
// 디렉토리인지 확인
103103
const stat = await fs.stat(workspaceInfo.workspaceDir);
104104
if (!stat.isDirectory()) {
@@ -114,24 +114,32 @@ export class WorkspaceSetup implements WorkspaceSetupInterface {
114114
});
115115
}
116116

117-
// Git worktree 검증 - worktree가 유효하지 않으면 workspace도 유효하지 않음
118-
if (this.dependencies.workspaceManager && typeof this.dependencies.workspaceManager.isWorktreeValid === 'function') {
119-
try {
120-
const isWorktreeValid = await this.dependencies.workspaceManager.isWorktreeValid(workspaceInfo);
121-
if (!isWorktreeValid) {
122-
this.dependencies.logger.warn('Worktree validation failed, workspace is invalid', {
117+
// Git worktree 검증 - worktree가 생성되었다고 표시된 경우에만 검증
118+
// 초기 셋팅 시에는 worktreeCreated가 false이므로 worktree 검증을 건너뜀
119+
if (workspaceInfo.worktreeCreated) {
120+
if (this.dependencies.workspaceManager && typeof this.dependencies.workspaceManager.isWorktreeValid === 'function') {
121+
try {
122+
const isWorktreeValid = await this.dependencies.workspaceManager.isWorktreeValid(workspaceInfo);
123+
if (!isWorktreeValid) {
124+
this.dependencies.logger.warn('Worktree validation failed, workspace is invalid', {
125+
taskId: workspaceInfo.taskId,
126+
reason: 'Git worktree is not valid'
127+
});
128+
return false;
129+
}
130+
} catch (worktreeError) {
131+
this.dependencies.logger.warn('Worktree validation error, workspace is invalid', {
123132
taskId: workspaceInfo.taskId,
124-
reason: 'Git worktree is not valid'
133+
error: worktreeError
125134
});
126135
return false;
127136
}
128-
} catch (worktreeError) {
129-
this.dependencies.logger.warn('Worktree validation error, workspace is invalid', {
130-
taskId: workspaceInfo.taskId,
131-
error: worktreeError
132-
});
133-
return false;
134137
}
138+
} else {
139+
this.dependencies.logger.debug('Skipping worktree validation (worktree not created yet)', {
140+
taskId: workspaceInfo.taskId,
141+
worktreeCreated: workspaceInfo.worktreeCreated
142+
});
135143
}
136144

137145
this.dependencies.logger.debug('Workspace environment validation passed', {

tests/unit/services/worker/workspace-setup.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,61 @@ describe('WorkspaceSetup', () => {
283283
}
284284
);
285285
});
286+
287+
it('초기 셋팅 시 worktreeCreated가 false이면 worktree 검증을 건너뛰어야 한다', async () => {
288+
// Given: 초기 셋팅으로 worktreeCreated가 false인 워크스페이스
289+
const initialWorkspaceInfo: WorkspaceInfo = {
290+
...workspaceInfo,
291+
worktreeCreated: false
292+
};
293+
294+
const fs = require('fs/promises');
295+
jest.spyOn(fs, 'access').mockResolvedValue(undefined);
296+
jest.spyOn(fs, 'stat').mockResolvedValue({
297+
isDirectory: () => true
298+
});
299+
300+
// When: 환경 검증
301+
const isValid = await workspaceSetup.validateEnvironment(initialWorkspaceInfo);
302+
303+
// Then: worktree 검증 없이 유효함
304+
expect(isValid).toBe(true);
305+
expect(mockWorkspaceManager.isWorktreeValid).not.toHaveBeenCalled();
306+
expect(mockLogger.debug).toHaveBeenCalledWith(
307+
'Skipping worktree validation (worktree not created yet)',
308+
{
309+
taskId: initialWorkspaceInfo.taskId,
310+
worktreeCreated: false
311+
}
312+
);
313+
expect(mockLogger.debug).toHaveBeenCalledWith(
314+
'Workspace environment validation passed',
315+
{ taskId: initialWorkspaceInfo.taskId }
316+
);
317+
});
318+
319+
it('worktreeCreated가 true이면 worktree 검증을 수행해야 한다', async () => {
320+
// Given: worktreeCreated가 true인 워크스페이스
321+
const fs = require('fs/promises');
322+
jest.spyOn(fs, 'access').mockResolvedValue(undefined);
323+
jest.spyOn(fs, 'stat').mockResolvedValue({
324+
isDirectory: () => true
325+
});
326+
327+
// isWorktreeValid가 true를 반환하도록 설정
328+
mockWorkspaceManager.isWorktreeValid.mockResolvedValue(true);
329+
330+
// When: 환경 검증
331+
const isValid = await workspaceSetup.validateEnvironment(workspaceInfo);
332+
333+
// Then: worktree 검증 수행
334+
expect(isValid).toBe(true);
335+
expect(mockWorkspaceManager.isWorktreeValid).toHaveBeenCalledWith(workspaceInfo);
336+
expect(mockLogger.debug).toHaveBeenCalledWith(
337+
'Workspace environment validation passed',
338+
{ taskId: workspaceInfo.taskId }
339+
);
340+
});
286341
});
287342

288343
describe('정리', () => {

0 commit comments

Comments
 (0)