mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
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.
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package slashcommands
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/hanzoteam/server/server/public/shared/request"
|
|
"github.com/hanzoteam/server/server/v8/channels/app"
|
|
"github.com/hanzoteam/server/server/v8/channels/utils"
|
|
)
|
|
|
|
type TestEnvironment struct {
|
|
Teams []*model.Team
|
|
Environments []TeamEnvironment
|
|
}
|
|
|
|
func CreateTestEnvironmentWithTeams(a *app.App, rctx request.CTX, client *model.Client4, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, error) {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
teamCreator := NewAutoTeamCreator(client)
|
|
teamCreator.Fuzzy = fuzzy
|
|
teams, err := teamCreator.CreateTestTeams(rangeTeams)
|
|
if err != nil {
|
|
return TestEnvironment{}, err
|
|
}
|
|
|
|
environment := TestEnvironment{teams, make([]TeamEnvironment, len(teams))}
|
|
|
|
for i, team := range teams {
|
|
userCreator := NewAutoUserCreator(a, client, team)
|
|
userCreator.Fuzzy = fuzzy
|
|
randomUser, err := userCreator.createRandomUser(rctx)
|
|
if err != nil {
|
|
return TestEnvironment{}, err
|
|
}
|
|
_, _, err = client.LoginById(context.Background(), randomUser.Id, UserPassword)
|
|
if err != nil {
|
|
return TestEnvironment{}, err
|
|
}
|
|
teamEnvironment, err := CreateTestEnvironmentInTeam(a, rctx, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
|
|
if err != nil {
|
|
return TestEnvironment{}, err
|
|
}
|
|
environment.Environments[i] = teamEnvironment
|
|
}
|
|
|
|
return environment, nil
|
|
}
|
|
|
|
func CreateTestEnvironmentInTeam(a *app.App, rctx request.CTX, client *model.Client4, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, error) {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
// We need to create at least one user
|
|
if rangeUsers.Begin <= 0 {
|
|
rangeUsers.Begin = 1
|
|
}
|
|
|
|
userCreator := NewAutoUserCreator(a, client, team)
|
|
userCreator.Fuzzy = fuzzy
|
|
users, err := userCreator.CreateTestUsers(rctx, rangeUsers)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
usernames := make([]string, len(users))
|
|
for i, user := range users {
|
|
usernames[i] = user.Username
|
|
}
|
|
|
|
channelCreator := NewAutoChannelCreator(a, team, users[0].Id)
|
|
channelCreator.Fuzzy = fuzzy
|
|
channels, err := channelCreator.CreateTestChannels(rctx, rangeChannels)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
|
|
// Have every user join every channel
|
|
for _, user := range users {
|
|
for _, channel := range channels {
|
|
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
|
|
_, _, err = client.AddChannelMember(context.Background(), channel.Id, user.Id)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
}
|
|
}
|
|
|
|
numPosts := utils.RandIntFromRange(rangePosts)
|
|
numImages := utils.RandIntFromRange(rangePosts) / 4
|
|
for range numPosts {
|
|
user := users[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(users) - 1})]
|
|
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
|
|
for i, channel := range channels {
|
|
postCreator := NewAutoPostCreator(a, channel.Id, user.Id)
|
|
postCreator.HasImage = i < numImages
|
|
postCreator.Users = usernames
|
|
postCreator.Fuzzy = fuzzy
|
|
_, err := postCreator.CreateRandomPost(rctx)
|
|
if err != nil {
|
|
return TeamEnvironment{}, err
|
|
}
|
|
}
|
|
}
|
|
|
|
return TeamEnvironment{users, channels}, nil
|
|
}
|