Skip to content

Commit 72e0d81

Browse files
committed
update
1 parent 17b25d0 commit 72e0d81

19 files changed

Lines changed: 2142 additions & 13 deletions

backend/modules/evaluation/application/experiment_app.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,14 +1188,14 @@ func (e *experimentApplication) DeleteExptInsightAnalysisRecord(ctx context.Cont
11881188

11891189
func (e *experimentApplication) GetExptInsightAnalysisRecord(ctx context.Context, req *expt.GetExptInsightAnalysisRecordRequest) (r *expt.GetExptInsightAnalysisRecordResponse, err error) {
11901190
session := &entity.Session{UserID: strconv.FormatInt(req.GetSession().GetUserID(), 10)}
1191-
//err = e.auth.Authorization(ctx, &rpc.AuthorizationParam{
1192-
// ObjectID: strconv.FormatInt(req.WorkspaceID, 10),
1193-
// SpaceID: req.WorkspaceID,
1194-
// ActionObjects: []*rpc.ActionObject{{Action: gptr.Of(consts.ActionReadExpt), EntityType: gptr.Of(rpc.AuthEntityType_Space)}},
1195-
//})
1196-
//if err != nil {
1197-
// return nil, err
1198-
//}
1191+
err = e.auth.Authorization(ctx, &rpc.AuthorizationParam{
1192+
ObjectID: strconv.FormatInt(req.WorkspaceID, 10),
1193+
SpaceID: req.WorkspaceID,
1194+
ActionObjects: []*rpc.ActionObject{{Action: gptr.Of(consts.ActionReadExpt), EntityType: gptr.Of(rpc.AuthEntityType_Space)}},
1195+
})
1196+
if err != nil {
1197+
return nil, err
1198+
}
11991199

12001200
record, err := e.GetAnalysisRecordByID(ctx, req.GetWorkspaceID(), req.GetExptID(), req.GetInsightAnalysisRecordID(), session)
12011201
if err != nil {
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// Copyright (c) 2025 coze-dev Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package application
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"go.uber.org/mock/gomock"
11+
12+
"github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/evaluation/domain/common"
13+
domain_expt "github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/evaluation/domain/expt"
14+
exptpb "github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/evaluation/expt"
15+
"github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/entity"
16+
repo_mocks "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/repo/mocks"
17+
servicemocks "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/service/mocks"
18+
rpcmocks "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/component/rpc/mocks"
19+
)
20+
21+
func setupTestApp(t *testing.T) (context.Context, *experimentApplication, *servicemocks.MockIExptManager, *repo_mocks.MockIExperimentRepo, *servicemocks.MockIExptInsightAnalysisService, *rpcmocks.MockIAuthProvider) {
22+
ctrl := gomock.NewController(t)
23+
mockManager := servicemocks.NewMockIExptManager(ctrl)
24+
mockRepo := repo_mocks.NewMockIExperimentRepo(ctrl)
25+
mockInsightService := servicemocks.NewMockIExptInsightAnalysisService(ctrl)
26+
mockAuth := rpcmocks.NewMockIAuthProvider(ctrl)
27+
28+
app := &experimentApplication{
29+
manager: mockManager,
30+
IExptInsightAnalysisService: mockInsightService,
31+
auth: mockAuth,
32+
}
33+
34+
return context.Background(), app, mockManager, mockRepo, mockInsightService, mockAuth
35+
}
36+
37+
func TestInsightAnalysisExperiment(t *testing.T) {
38+
ctx, app, mockManager, _, mockInsightService, mockAuth := setupTestApp(t)
39+
40+
req := &exptpb.InsightAnalysisExperimentRequest{
41+
WorkspaceID: 123,
42+
ExptID: 456,
43+
Session: &common.Session{
44+
UserID: &[]int64{789}[0],
45+
},
46+
}
47+
48+
// Mock the manager.Get call
49+
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
50+
// Mock the auth.AuthorizationWithoutSPI call
51+
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
52+
// Mock the CreateAnalysisRecord call
53+
mockInsightService.EXPECT().CreateAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any()).Return(int64(123), nil)
54+
55+
_, err := app.InsightAnalysisExperiment(ctx, req)
56+
if err != nil {
57+
t.Errorf("InsightAnalysisExperiment failed: %v", err)
58+
}
59+
}
60+
61+
func TestListExptInsightAnalysisRecord(t *testing.T) {
62+
ctx, app, mockManager, _, mockInsightService, mockAuth := setupTestApp(t)
63+
64+
req := &exptpb.ListExptInsightAnalysisRecordRequest{
65+
WorkspaceID: 123,
66+
ExptID: 456,
67+
PageNumber: &[]int32{1}[0],
68+
PageSize: &[]int32{10}[0],
69+
Session: &common.Session{
70+
UserID: &[]int64{789}[0],
71+
},
72+
}
73+
74+
// Mock the manager.Get call
75+
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
76+
// Mock the auth.AuthorizationWithoutSPI call
77+
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
78+
mockInsightService.EXPECT().ListAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return([]*entity.ExptInsightAnalysisRecord{}, int64(0), nil)
79+
80+
_, err := app.ListExptInsightAnalysisRecord(ctx, req)
81+
if err != nil {
82+
t.Errorf("ListExptInsightAnalysisRecord failed: %v", err)
83+
}
84+
}
85+
86+
func TestGetExptInsightAnalysisRecord(t *testing.T) {
87+
ctx, app, _, _, mockInsightService, mockAuth := setupTestApp(t)
88+
89+
userID := int64(789)
90+
req := &exptpb.GetExptInsightAnalysisRecordRequest{
91+
WorkspaceID: 123,
92+
ExptID: 456,
93+
InsightAnalysisRecordID: 789,
94+
Session: &common.Session{
95+
UserID: &userID,
96+
},
97+
}
98+
99+
// Mock the auth.Authorization call
100+
mockAuth.EXPECT().Authorization(gomock.Any(), gomock.Any()).Return(nil)
101+
// Mock the service call
102+
mockInsightService.EXPECT().GetAnalysisRecordByID(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.ExptInsightAnalysisRecord{
103+
ID: 789,
104+
ExptID: 456,
105+
SpaceID: 123,
106+
Status: entity.InsightAnalysisStatus_Running,
107+
CreatedBy: "test-user",
108+
}, nil)
109+
110+
resp, err := app.GetExptInsightAnalysisRecord(ctx, req)
111+
if err != nil {
112+
t.Errorf("GetExptInsightAnalysisRecord failed: %v", err)
113+
}
114+
if resp == nil {
115+
t.Error("Expected non-nil response")
116+
}
117+
}
118+
119+
func TestDeleteExptInsightAnalysisRecord(t *testing.T) {
120+
ctx, app, mockManager, _, mockInsightService, mockAuth := setupTestApp(t)
121+
122+
req := &exptpb.DeleteExptInsightAnalysisRecordRequest{
123+
WorkspaceID: 123,
124+
ExptID: 456,
125+
InsightAnalysisRecordID: 789,
126+
Session: &common.Session{
127+
UserID: &[]int64{789}[0],
128+
},
129+
}
130+
131+
// Mock the manager.Get call
132+
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
133+
// Mock the auth.AuthorizationWithoutSPI call
134+
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
135+
mockInsightService.EXPECT().DeleteAnalysisRecord(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
136+
137+
_, err := app.DeleteExptInsightAnalysisRecord(ctx, req)
138+
if err != nil {
139+
t.Errorf("DeleteExptInsightAnalysisRecord failed: %v", err)
140+
}
141+
}
142+
143+
func TestFeedbackExptInsightAnalysisReport(t *testing.T) {
144+
ctx, app, mockManager, _, mockInsightService, mockAuth := setupTestApp(t)
145+
146+
req := &exptpb.FeedbackExptInsightAnalysisReportRequest{
147+
WorkspaceID: 123,
148+
ExptID: 456,
149+
InsightAnalysisRecordID: 789,
150+
FeedbackActionType: domain_expt.FeedbackActionTypeUpvote,
151+
Session: &common.Session{
152+
UserID: &[]int64{789}[0],
153+
},
154+
}
155+
156+
// Mock the manager.Get call
157+
mockManager.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&entity.Experiment{CreatedBy: "test-user"}, nil)
158+
// Mock the auth.AuthorizationWithoutSPI call
159+
mockAuth.EXPECT().AuthorizationWithoutSPI(gomock.Any(), gomock.Any()).Return(nil)
160+
mockInsightService.EXPECT().FeedbackExptInsightAnalysis(gomock.Any(), gomock.Any()).Return(nil)
161+
162+
_, err := app.FeedbackExptInsightAnalysisReport(ctx, req)
163+
if err != nil {
164+
t.Errorf("FeedbackExptInsightAnalysisReport failed: %v", err)
165+
}
166+
}
167+
168+
func TestListExptInsightAnalysisComment(t *testing.T) {
169+
ctx, app, _, _, mockInsightService, mockAuth := setupTestApp(t)
170+
171+
req := &exptpb.ListExptInsightAnalysisCommentRequest{
172+
WorkspaceID: 123,
173+
ExptID: 456,
174+
InsightAnalysisRecordID: 789,
175+
PageNumber: &[]int32{1}[0],
176+
PageSize: &[]int32{10}[0],
177+
Session: &common.Session{
178+
UserID: &[]int64{789}[0],
179+
},
180+
}
181+
182+
// Mock the auth.Authorization call
183+
mockAuth.EXPECT().Authorization(gomock.Any(), gomock.Any()).Return(nil)
184+
mockInsightService.EXPECT().ListExptInsightAnalysisFeedbackComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return([]*entity.ExptInsightAnalysisFeedbackComment{}, int64(0), nil)
185+
186+
_, err := app.ListExptInsightAnalysisComment(ctx, req)
187+
if err != nil {
188+
t.Errorf("ListExptInsightAnalysisComment failed: %v", err)
189+
}
190+
}

backend/modules/evaluation/domain/component/rpc/mocks/notify.go

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/modules/evaluation/domain/component/rpc/mocks/trace_agent.go

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/modules/evaluation/domain/component/rpc/notify.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rpc
22

33
import "context"
44

5+
//go:generate mockgen -destination=mocks/notify.go -package=mocks . INotifyRPCAdapter
56
type INotifyRPCAdapter interface {
67
SendLarkMessageCard(ctx context.Context, userID, cardID string, param map[string]string) error
78
}

backend/modules/evaluation/domain/component/rpc/trace_agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/entity"
1010
)
1111

12-
//go:generate mockgen -destination=mocks/auth_provider.go -package=mocks . IAuthProvider
12+
//go:generate mockgen -destination=mocks/trace_agent.go -package=mocks . IAgentAdapter
1313
type IAgentAdapter interface {
1414
CallTraceAgent(ctx context.Context, spaceID int64, url string) (int64, error)
1515
GetReport(ctx context.Context, spaceID, reportID int64) (report string, status entity.ReportStatus, err error)

backend/modules/evaluation/domain/repo/expt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/entity"
1111
)
1212

13-
//go:generate mockgen -destination ./mocks/expt.go --package mocks . IExperimentRepo,IExptStatsRepo,IExptItemResultRepo,IExptTurnResultRepo,IExptRunLogRepo,IExptAggrResultRepo,QuotaRepo,IExptTurnResultFilterRepo,IExptAnnotateRepo,IExptResultExportRecordRepo
13+
//go:generate mockgen -destination ./mocks/expt.go --package mocks . IExperimentRepo,IExptStatsRepo,IExptItemResultRepo,IExptTurnResultRepo,IExptRunLogRepo,IExptAggrResultRepo,QuotaRepo,IExptTurnResultFilterRepo,IExptAnnotateRepo,IExptResultExportRecordRepo,IExptInsightAnalysisRecordRepo
1414
type IExperimentRepo interface {
1515
Create(ctx context.Context, expt *entity.Experiment, exptEvaluatorRefs []*entity.ExptEvaluatorRef) error
1616
Update(ctx context.Context, expt *entity.Experiment) error

0 commit comments

Comments
 (0)