You've already forked agentic-coding-workflow
fix: address code review — error-path tests, edge cases, UX improvements
This commit is contained in:
@@ -250,6 +250,22 @@ func (t *trackGit) Checkout(_ context.Context, _, branch string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type errFetchGit struct {
|
||||
git.Runner
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *errFetchGit) FetchRemoteBranch(_ context.Context, _, _ string, _ *git.Credential) error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
type errCheckoutGit struct {
|
||||
git.Runner
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *errCheckoutGit) Checkout(_ context.Context, _, _ string) error { return e.err }
|
||||
|
||||
type noopAudit struct{}
|
||||
|
||||
func (noopAudit) Record(_ context.Context, _ audit.Entry) error { return nil }
|
||||
@@ -404,11 +420,9 @@ func TestCloneRunner_Failure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWorkspaceService_Update_DefaultBranch_Switch(t *testing.T) {
|
||||
// 切换 default_branch 时,service 必须先 fetch+checkout 远端分支,再落库。
|
||||
// 注意:fakeGit 默认 stub 不会记录调用,本测试仅断言最终 DB 状态。
|
||||
t.Parallel()
|
||||
pa := &fakePA{pid: uuid.New(), canRead: true, canWrite: true}
|
||||
fg := &fakeGit{}
|
||||
fg := &trackGit{Runner: &fakeGit{}}
|
||||
svc, repo := newSvc(t, pa, nil, fg)
|
||||
caller := Caller{UserID: uuid.New()}
|
||||
|
||||
@@ -426,6 +440,52 @@ func TestWorkspaceService_Update_DefaultBranch_Switch(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "develop", repo.wss[wsID].DefaultBranch)
|
||||
require.Equal(t, []string{"develop"}, fg.fetchRemoteBranchCalls)
|
||||
require.Equal(t, []string{"develop"}, fg.checkoutCalls)
|
||||
}
|
||||
|
||||
func TestWorkspaceService_Update_DefaultBranch_FetchFails(t *testing.T) {
|
||||
t.Parallel()
|
||||
pa := &fakePA{pid: uuid.New(), canRead: true, canWrite: true}
|
||||
fg := &errFetchGit{Runner: &fakeGit{}, err: errors.New("remote branch not found")}
|
||||
svc, repo := newSvc(t, pa, nil, fg)
|
||||
caller := Caller{UserID: uuid.New()}
|
||||
|
||||
wsID := uuid.New()
|
||||
repo.wss[wsID] = &Workspace{
|
||||
ID: wsID, ProjectID: pa.pid, Slug: "ws1", Name: "W1",
|
||||
DefaultBranch: "main", MainPath: "/data/ws1/main",
|
||||
}
|
||||
|
||||
newBr := "nonexistent"
|
||||
_, err := svc.Update(context.Background(), caller, wsID, UpdateWorkspaceInput{
|
||||
DefaultBranch: &newBr,
|
||||
})
|
||||
require.Error(t, err)
|
||||
// DB should NOT be updated
|
||||
require.Equal(t, "main", repo.wss[wsID].DefaultBranch)
|
||||
}
|
||||
|
||||
func TestWorkspaceService_Update_DefaultBranch_CheckoutFails(t *testing.T) {
|
||||
t.Parallel()
|
||||
pa := &fakePA{pid: uuid.New(), canRead: true, canWrite: true}
|
||||
fg := &errCheckoutGit{Runner: &fakeGit{}, err: errors.New("dirty working tree")}
|
||||
svc, repo := newSvc(t, pa, nil, fg)
|
||||
caller := Caller{UserID: uuid.New()}
|
||||
|
||||
wsID := uuid.New()
|
||||
repo.wss[wsID] = &Workspace{
|
||||
ID: wsID, ProjectID: pa.pid, Slug: "ws1", Name: "W1",
|
||||
DefaultBranch: "main", MainPath: "/data/ws1/main",
|
||||
}
|
||||
|
||||
newBr := "develop"
|
||||
_, err := svc.Update(context.Background(), caller, wsID, UpdateWorkspaceInput{
|
||||
DefaultBranch: &newBr,
|
||||
})
|
||||
require.Error(t, err)
|
||||
// DB should NOT be updated
|
||||
require.Equal(t, "main", repo.wss[wsID].DefaultBranch)
|
||||
}
|
||||
|
||||
func TestWorkspaceService_Update_DefaultBranch_SameValue_NoGitOps(t *testing.T) {
|
||||
@@ -460,7 +520,7 @@ func TestWorkspaceService_ListBranches(t *testing.T) {
|
||||
wsID := uuid.New()
|
||||
repo.wss[wsID] = &Workspace{
|
||||
ID: wsID, ProjectID: pa.pid, Slug: "ws1",
|
||||
DefaultBranch: "main", MainPath: "/data/ws1/main",
|
||||
DefaultBranch: "main", MainPath: t.TempDir(),
|
||||
}
|
||||
|
||||
branches, err := svc.ListBranches(context.Background(), caller, wsID)
|
||||
|
||||
Reference in New Issue
Block a user