From 5e26ed605031b14bc39d05802225a7be8fd3ab4e Mon Sep 17 00:00:00 2001 From: Sho DOUHASHI Date: Tue, 4 Nov 2025 01:59:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20worktree=E3=81=AE=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E5=85=88=E3=82=92/tmp/soba/worktrees=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - デフォルトのworktree作成先を.git/soba/worktreesから/tmp/soba/worktreesに変更 - config_template.ymlのデフォルト値を更新 - 全てのテストファイルのパスを新しいデフォルト値に更新 - 後方互換性は不要のため、既存のworktreeについては手動での移行が必要 --- internal/cli/config_test.go | 4 +-- internal/cli/init_test.go | 2 +- internal/config/config_template.yml | 4 +-- internal/config/config_test.go | 10 +++--- internal/config/defaults.go | 2 +- internal/config/display_test.go | 4 +-- internal/config/template_test.go | 4 +-- internal/service/daemon_test.go | 2 +- internal/service/git_workspace_test.go | 36 +++++++++++----------- internal/service/integration_test.go | 2 +- internal/service/workflow_executor_test.go | 12 ++++---- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/internal/cli/config_test.go b/internal/cli/config_test.go index ea9e799..43a4d67 100644 --- a/internal/cli/config_test.go +++ b/internal/cli/config_test.go @@ -44,7 +44,7 @@ func TestRunConfig_Success(t *testing.T) { NotificationsEnabled: false, }, Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, Phase: config.PhaseConfig{ Plan: config.PhaseCommand{ @@ -109,7 +109,7 @@ log: assert.NotNil(t, cfg) // Verify defaults are set assert.Equal(t, 20, cfg.Workflow.Interval) - assert.Equal(t, ".git/soba/worktrees", cfg.Git.WorktreeBasePath) + assert.Equal(t, "/tmp/soba/worktrees", cfg.Git.WorktreeBasePath) } func TestRunConfig_InvalidYAML(t *testing.T) { diff --git a/internal/cli/init_test.go b/internal/cli/init_test.go index 6b019f4..0839700 100644 --- a/internal/cli/init_test.go +++ b/internal/cli/init_test.go @@ -185,7 +185,7 @@ func TestInitCommand(t *testing.T) { assert.Equal(t, "test-owner/test-repo", loadedConfig.GitHub.Repository) assert.Equal(t, 20, loadedConfig.Workflow.Interval) assert.True(t, loadedConfig.Workflow.UseTmux) - assert.Equal(t, ".git/soba/worktrees", loadedConfig.Git.WorktreeBasePath) + assert.Equal(t, "/tmp/soba/worktrees", loadedConfig.Git.WorktreeBasePath) }) t.Run("should create GitHub labels when config has repository info", func(t *testing.T) { diff --git a/internal/config/config_template.yml b/internal/config/config_template.yml index f0ba67b..507fb94 100644 --- a/internal/config/config_template.yml +++ b/internal/config/config_template.yml @@ -37,8 +37,8 @@ slack: # Git settings git: - # Base path for git worktrees - worktree_base_path: .git/soba/worktrees + # Base path for git worktrees (default: /tmp/soba/worktrees) + worktree_base_path: /tmp/soba/worktrees # Base branch for rebase operations and worktree creation (default: main) base_branch: main diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 58f0907..020d1e4 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -157,8 +157,8 @@ github: t.Errorf("Default tmux command delay = %v, want 3", cfg.Workflow.TmuxCommandDelay) } - if cfg.Git.WorktreeBasePath != ".git/soba/worktrees" { - t.Errorf("Default git worktree base path = %v, want .git/soba/worktrees", cfg.Git.WorktreeBasePath) + if cfg.Git.WorktreeBasePath != "/tmp/soba/worktrees" { + t.Errorf("Default git worktree base path = %v, want /tmp/soba/worktrees", cfg.Git.WorktreeBasePath) } } @@ -175,8 +175,8 @@ func TestLoadConfigFileNotFound(t *testing.T) { if cfg != nil && cfg.Workflow.Interval != 20 { t.Errorf("Default workflow interval = %v, want 20", cfg.Workflow.Interval) } - if cfg != nil && cfg.Git.WorktreeBasePath != ".git/soba/worktrees" { - t.Errorf("Default git worktree base path = %v, want .git/soba/worktrees", cfg.Git.WorktreeBasePath) + if cfg != nil && cfg.Git.WorktreeBasePath != "/tmp/soba/worktrees" { + t.Errorf("Default git worktree base path = %v, want /tmp/soba/worktrees", cfg.Git.WorktreeBasePath) } expectedLogPath := fmt.Sprintf(".soba/logs/soba-%d.log", os.Getpid()) if cfg != nil && cfg.Log.OutputPath != expectedLogPath { @@ -225,7 +225,7 @@ func TestConfigStructFields(t *testing.T) { NotificationsEnabled: true, }, Git: GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, Phase: PhaseConfig{ Plan: PhaseCommand{ diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 9c20f92..62e9307 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -4,5 +4,5 @@ const ( DefaultWorkflowInterval = 20 DefaultClosedIssueCleanupInterval = 300 DefaultTmuxCommandDelay = 3 - DefaultWorktreeBasePath = ".git/soba/worktrees" + DefaultWorktreeBasePath = "/tmp/soba/worktrees" ) diff --git a/internal/config/display_test.go b/internal/config/display_test.go index 38d763e..083aabd 100644 --- a/internal/config/display_test.go +++ b/internal/config/display_test.go @@ -119,7 +119,7 @@ func TestDisplayConfig(t *testing.T) { NotificationsEnabled: true, }, Git: GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, Phase: PhaseConfig{ Plan: PhaseCommand{ @@ -142,7 +142,7 @@ func TestDisplayConfig(t *testing.T) { assert.Contains(t, output, "repository: test/repo") assert.Contains(t, output, "interval: 30") assert.Contains(t, output, "use_tmux: true") - assert.Contains(t, output, "worktree_base_path: .git/soba/worktrees") + assert.Contains(t, output, "worktree_base_path: /tmp/soba/worktrees") // YAML形式であることを確認 lines := strings.Split(output, "\n") diff --git a/internal/config/template_test.go b/internal/config/template_test.go index 998ba05..dcea675 100644 --- a/internal/config/template_test.go +++ b/internal/config/template_test.go @@ -44,7 +44,7 @@ func TestGenerateTemplate(t *testing.T) { assert.Contains(t, template, "tmux_command_delay: 3") assert.Contains(t, template, "notifications_enabled: false") assert.NotContains(t, template, "setup_workspace") - assert.Contains(t, template, "worktree_base_path: .git/soba/worktrees") + assert.Contains(t, template, "worktree_base_path: /tmp/soba/worktrees") }) t.Run("should include environment variable placeholders", func(t *testing.T) { @@ -103,7 +103,7 @@ func TestGenerateTemplate(t *testing.T) { assert.Equal(t, 300, config.Workflow.ClosedIssueCleanupInterval) assert.Equal(t, 3, config.Workflow.TmuxCommandDelay) assert.False(t, config.Slack.NotificationsEnabled) - assert.Equal(t, ".git/soba/worktrees", config.Git.WorktreeBasePath) + assert.Equal(t, "/tmp/soba/worktrees", config.Git.WorktreeBasePath) // Verify phase commands assert.NotNil(t, config.Phase) diff --git a/internal/service/daemon_test.go b/internal/service/daemon_test.go index b09c3f7..5a8f949 100644 --- a/internal/service/daemon_test.go +++ b/internal/service/daemon_test.go @@ -42,7 +42,7 @@ func TestNewDaemonServiceWithConfig(t *testing.T) { Interval: 20, }, Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, } diff --git a/internal/service/git_workspace_test.go b/internal/service/git_workspace_test.go index 2681692..5a3ae5f 100644 --- a/internal/service/git_workspace_test.go +++ b/internal/service/git_workspace_test.go @@ -39,7 +39,7 @@ func (m *mockGitClient) WorktreeExists(worktreePath string) bool { func TestNewGitWorkspaceManager(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } @@ -60,7 +60,7 @@ func TestGitWorkspaceManager_PrepareWorkspace(t *testing.T) { name: "Successfully prepare new workspace", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(false) mc.On("UpdateBaseBranch", "main").Return(nil) mc.On("CreateWorktree", expectedPath, "soba/33", "main").Return(nil) @@ -71,7 +71,7 @@ func TestGitWorkspaceManager_PrepareWorkspace(t *testing.T) { name: "Workspace already exists", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(true) }, wantErr: false, @@ -80,7 +80,7 @@ func TestGitWorkspaceManager_PrepareWorkspace(t *testing.T) { name: "Failed to update base branch", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(false) mc.On("UpdateBaseBranch", "main").Return(assert.AnError) }, @@ -90,7 +90,7 @@ func TestGitWorkspaceManager_PrepareWorkspace(t *testing.T) { name: "Failed to create worktree", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(false) mc.On("UpdateBaseBranch", "main").Return(nil) mc.On("CreateWorktree", expectedPath, "soba/33", "main").Return(assert.AnError) @@ -109,7 +109,7 @@ func TestGitWorkspaceManager_PrepareWorkspace(t *testing.T) { t.Run(tt.name, func(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } @@ -140,7 +140,7 @@ func TestGitWorkspaceManager_CleanupWorkspace(t *testing.T) { name: "Successfully cleanup workspace", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(true) mc.On("RemoveWorktree", expectedPath).Return(nil) }, @@ -150,7 +150,7 @@ func TestGitWorkspaceManager_CleanupWorkspace(t *testing.T) { name: "Workspace does not exist", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(false) }, wantErr: false, @@ -159,7 +159,7 @@ func TestGitWorkspaceManager_CleanupWorkspace(t *testing.T) { name: "Failed to remove worktree", issueNumber: 33, setupMocks: func(mc *mockGitClient) { - expectedPath := filepath.Join(".git/soba/worktrees", "issue-33") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-33") mc.On("WorktreeExists", expectedPath).Return(true) mc.On("RemoveWorktree", expectedPath).Return(assert.AnError) }, @@ -177,7 +177,7 @@ func TestGitWorkspaceManager_CleanupWorkspace(t *testing.T) { t.Run(tt.name, func(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } @@ -200,7 +200,7 @@ func TestGitWorkspaceManager_CleanupWorkspace(t *testing.T) { func TestGitWorkspaceManager_GetWorkspacePath(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } @@ -215,12 +215,12 @@ func TestGitWorkspaceManager_GetWorkspacePath(t *testing.T) { { name: "Valid issue number", issueNumber: 33, - want: filepath.Join(".git/soba/worktrees", "issue-33"), + want: filepath.Join("/tmp/soba/worktrees", "issue-33"), }, { name: "Large issue number", issueNumber: 999, - want: filepath.Join(".git/soba/worktrees", "issue-999"), + want: filepath.Join("/tmp/soba/worktrees", "issue-999"), }, } @@ -235,7 +235,7 @@ func TestGitWorkspaceManager_GetWorkspacePath(t *testing.T) { func TestGitWorkspaceManager_GetBranchName(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } @@ -270,13 +270,13 @@ func TestGitWorkspaceManager_GetBranchName(t *testing.T) { func TestGitWorkspaceManager_WithCustomBaseBranch(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "develop", }, } mockClient := new(mockGitClient) - expectedPath := filepath.Join(".git/soba/worktrees", "issue-42") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-42") mockClient.On("WorktreeExists", expectedPath).Return(false) mockClient.On("UpdateBaseBranch", "develop").Return(nil) mockClient.On("CreateWorktree", expectedPath, "soba/42", "develop").Return(nil) @@ -293,13 +293,13 @@ func TestGitWorkspaceManager_PrepareWorkspace_UpdatesBaseBranch(t *testing.T) { // before creating a new worktree, ensuring we have the latest code cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, } mockClient := new(mockGitClient) - expectedPath := filepath.Join(".git/soba/worktrees", "issue-100") + expectedPath := filepath.Join("/tmp/soba/worktrees", "issue-100") // Setup expectations: UpdateBaseBranch must be called before CreateWorktree mockClient.On("WorktreeExists", expectedPath).Return(false) diff --git a/internal/service/integration_test.go b/internal/service/integration_test.go index 4b175cc..f13377c 100644 --- a/internal/service/integration_test.go +++ b/internal/service/integration_test.go @@ -76,7 +76,7 @@ func TestIntegration_FullWorkflow(t *testing.T) { Repository: "test/repo", }, Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, Workflow: config.WorkflowConfig{ Interval: 1, diff --git a/internal/service/workflow_executor_test.go b/internal/service/workflow_executor_test.go index 70ed5d8..97f678c 100644 --- a/internal/service/workflow_executor_test.go +++ b/internal/service/workflow_executor_test.go @@ -154,7 +154,7 @@ func TestWorkflowExecutor_ExecutePhase(t *testing.T) { tmux.On("CreateWindow", "soba-test-repo", "issue-456").Return(nil) // Window was created, so no pane management tmux.On("GetLastPaneIndex", "soba-test-repo", "issue-456").Return(0, nil) - tmux.On("SendCommand", "soba-test-repo", "issue-456", 0, `cd .git/soba/worktrees/issue-456 && echo "Planning"`).Return(nil) + tmux.On("SendCommand", "soba-test-repo", "issue-456", 0, `cd /tmp/soba/worktrees/issue-456 && echo "Planning"`).Return(nil) }, wantErr: false, }, @@ -176,7 +176,7 @@ func TestWorkflowExecutor_ExecutePhase(t *testing.T) { tmux.On("CreatePane", "soba-test-repo", "issue-789").Return(nil) tmux.On("ResizePanes", "soba-test-repo", "issue-789").Return(nil) tmux.On("GetLastPaneIndex", "soba-test-repo", "issue-789").Return(2, nil) // 送信用(新しいペイン) - tmux.On("SendCommand", "soba-test-repo", "issue-789", 2, `cd .git/soba/worktrees/issue-789 && echo "Implementing"`).Return(nil) + tmux.On("SendCommand", "soba-test-repo", "issue-789", 2, `cd /tmp/soba/worktrees/issue-789 && echo "Implementing"`).Return(nil) }, wantErr: false, }, @@ -226,7 +226,7 @@ func TestWorkflowExecutor_ExecutePhase(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, GitHub: config.GitHubConfig{ Repository: "test/repo", @@ -356,13 +356,13 @@ func TestWorkflowExecutor_ExecutePhase_WithWorktreePreparation(t *testing.T) { mockTmux.On("CreateWindow", "soba-test-repo", "issue-1").Return(nil) // Window was created, so no pane management mockTmux.On("GetLastPaneIndex", "soba-test-repo", "issue-1").Return(0, nil) - mockTmux.On("SendCommand", "soba-test-repo", "issue-1", 0, `cd .git/soba/worktrees/issue-1 && soba:plan "1"`).Return(nil) + mockTmux.On("SendCommand", "soba-test-repo", "issue-1", 0, `cd /tmp/soba/worktrees/issue-1 && soba:plan "1"`).Return(nil) executor := NewWorkflowExecutor(mockTmux, mockWorkspace, mockProcessor, logging.NewMockLogger()) cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", }, GitHub: config.GitHubConfig{ Repository: "test/repo", @@ -678,7 +678,7 @@ func TestWorkflowExecutor_PrepareWorkspaceWithBaseBranchUpdate(t *testing.T) { cfg := &config.Config{ Git: config.GitConfig{ - WorktreeBasePath: ".git/soba/worktrees", + WorktreeBasePath: "/tmp/soba/worktrees", BaseBranch: "main", }, GitHub: config.GitHubConfig{