Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

168 lines
6.1 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package recap
import (
"testing"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/shared/mlog"
"github.com/hanzoteam/server/server/public/shared/request"
"github.com/hanzoteam/server/server/v8/channels/store/storetest/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type MockAppIface struct {
mock.Mock
}
func (m *MockAppIface) ProcessRecapChannelWithOptions(rctx request.CTX, recapID, channelID, userID, agentID string, options model.RecapProcessingOptions) (*model.RecapChannelResult, *model.AppError) {
args := m.Called(rctx, recapID, channelID, userID, agentID, options)
if args.Get(0) == nil {
return nil, args.Get(1).(*model.AppError)
}
return args.Get(0).(*model.RecapChannelResult), nil
}
func (m *MockAppIface) Publish(message *model.WebSocketEvent) {
m.Called(message)
}
func TestProcessRecapJob(t *testing.T) {
logger := mlog.CreateConsoleTestLogger(t)
job := &model.Job{
Data: map[string]string{
"recap_id": "recap1",
"user_id": "user1",
"channel_ids": "channel1,channel2",
"agent_id": "agent1",
},
}
t.Run("successful processing", func(t *testing.T) {
mockStore := &mocks.Store{}
mockRecapStore := &mocks.RecapStore{}
mockStore.On("Recap").Return(mockRecapStore)
mockApp := &MockAppIface{}
// Setup expectations
mockRecapStore.On("UpdateRecapStatus", "recap1", model.RecapStatusProcessing).Return(nil)
mockApp.On("Publish", mock.Anything).Return()
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel1", "user1", "agent1", model.RecapProcessingOptions{}).Return(&model.RecapChannelResult{
ChannelID: "channel1",
Success: true,
MessageCount: 10,
}, nil)
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel2", "user1", "agent1", model.RecapProcessingOptions{}).Return(&model.RecapChannelResult{
ChannelID: "channel2",
Success: true,
MessageCount: 5,
}, nil)
recap := &model.Recap{Id: "recap1"}
mockRecapStore.On("GetRecap", "recap1").Return(recap, nil)
mockRecapStore.On("UpdateRecap", mock.MatchedBy(func(r *model.Recap) bool {
return r.TotalMessageCount == 15 && r.Status == model.RecapStatusCompleted
})).Return(recap, nil)
err := processRecapJob(logger, job, mockStore, mockApp, nil)
require.NoError(t, err)
})
t.Run("partial failure", func(t *testing.T) {
mockStore := &mocks.Store{}
mockRecapStore := &mocks.RecapStore{}
mockStore.On("Recap").Return(mockRecapStore)
mockApp := &MockAppIface{}
mockRecapStore.On("UpdateRecapStatus", "recap1", model.RecapStatusProcessing).Return(nil)
mockApp.On("Publish", mock.Anything).Return()
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel1", "user1", "agent1", model.RecapProcessingOptions{}).Return(&model.RecapChannelResult{
ChannelID: "channel1",
Success: true,
MessageCount: 10,
}, nil)
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel2", "user1", "agent1", model.RecapProcessingOptions{}).Return(nil, model.NewAppError("fail", "fail", nil, "", 500))
recap := &model.Recap{Id: "recap1"}
mockRecapStore.On("GetRecap", "recap1").Return(recap, nil)
mockRecapStore.On("UpdateRecap", mock.MatchedBy(func(r *model.Recap) bool {
return r.TotalMessageCount == 10 && r.Status == model.RecapStatusCompleted
})).Return(recap, nil)
err := processRecapJob(logger, job, mockStore, mockApp, nil)
require.NoError(t, err)
})
t.Run("complete failure", func(t *testing.T) {
mockStore := &mocks.Store{}
mockRecapStore := &mocks.RecapStore{}
mockStore.On("Recap").Return(mockRecapStore)
mockApp := &MockAppIface{}
mockRecapStore.On("UpdateRecapStatus", "recap1", model.RecapStatusProcessing).Return(nil)
mockApp.On("Publish", mock.Anything).Return()
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel1", "user1", "agent1", model.RecapProcessingOptions{}).Return(nil, model.NewAppError("fail", "fail", nil, "", 500))
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel2", "user1", "agent1", model.RecapProcessingOptions{}).Return(nil, model.NewAppError("fail", "fail", nil, "", 500))
recap := &model.Recap{Id: "recap1"}
mockRecapStore.On("GetRecap", "recap1").Return(recap, nil)
mockRecapStore.On("UpdateRecap", mock.MatchedBy(func(r *model.Recap) bool {
return r.TotalMessageCount == 0 && r.Status == model.RecapStatusFailed
})).Return(recap, nil)
err := processRecapJob(logger, job, mockStore, mockApp, nil)
require.Error(t, err)
require.Equal(t, "all channels failed to process", err.Error())
})
t.Run("passes scheduled options to channel processing", func(t *testing.T) {
jobWithOptions := &model.Job{
Data: map[string]string{
"recap_id": "recap1",
"user_id": "user1",
"channel_ids": "channel1",
"agent_id": "agent1",
"time_period": model.TimePeriodLastWeek,
"custom_instructions": "Focus on blockers",
},
}
mockStore := &mocks.Store{}
mockRecapStore := &mocks.RecapStore{}
mockStore.On("Recap").Return(mockRecapStore)
mockApp := &MockAppIface{}
mockRecapStore.On("UpdateRecapStatus", "recap1", model.RecapStatusProcessing).Return(nil)
mockApp.On("Publish", mock.Anything).Return()
mockApp.On("ProcessRecapChannelWithOptions", mock.Anything, "recap1", "channel1", "user1", "agent1", model.RecapProcessingOptions{
TimePeriod: model.TimePeriodLastWeek,
CustomInstructions: "Focus on blockers",
}).Return(&model.RecapChannelResult{
ChannelID: "channel1",
Success: true,
MessageCount: 3,
}, nil)
recap := &model.Recap{Id: "recap1"}
mockRecapStore.On("GetRecap", "recap1").Return(recap, nil)
mockRecapStore.On("UpdateRecap", mock.MatchedBy(func(r *model.Recap) bool {
return r.TotalMessageCount == 3 && r.Status == model.RecapStatusCompleted
})).Return(recap, nil)
err := processRecapJob(logger, jobWithOptions, mockStore, mockApp, nil)
require.NoError(t, err)
mockApp.AssertExpectations(t)
})
}