MCPcopy Create free account
hub / github.com/coder/coder / TestListChats_OrgAdminOnlySeesOwnChats

Function TestListChats_OrgAdminOnlySeesOwnChats

enterprise/coderd/exp_chats_test.go:1150–1256  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1148}
1149
1150func TestListChats_OrgAdminOnlySeesOwnChats(t *testing.T) {
1151 t.Parallel()
1152
1153 ctx := testutil.Context(t, testutil.WaitLong)
1154
1155 client, firstUser := coderdenttest.New(t, &coderdenttest.Options{
1156 Options: &coderdtest.Options{
1157 DeploymentValues: func() *codersdk.DeploymentValues {
1158 v := coderdtest.DeploymentValues(t)
1159 return v
1160 }(),
1161 },
1162 LicenseOptions: &coderdenttest.LicenseOptions{
1163 Features: license.Features{
1164 codersdk.FeatureMultipleOrganizations: 1,
1165 },
1166 },
1167 })
1168 expClient := codersdk.NewExperimentalClient(client)
1169
1170 provider := createOpenAIProviderForTest(ctx, t, expClient, "test-key", "https://example.com")
1171 _, err := expClient.CreateChatModelConfig(ctx, codersdk.CreateChatModelConfigRequest{
1172 Provider: string(provider.Type),
1173 AIProviderID: &provider.ID,
1174 Model: "gpt-4o-mini",
1175 DisplayName: "Test Model",
1176 IsDefault: ptr.Ref(true),
1177 ContextLimit: ptr.Ref(int64(1000)),
1178 CompressionThreshold: ptr.Ref(int32(70)),
1179 })
1180 require.NoError(t, err)
1181
1182 // Create a second (non-default) org.
1183 secondOrg := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{})
1184
1185 // Create a member with agents-access in both orgs.
1186 memberClientRaw, _ := coderdtest.CreateAnotherUser(
1187 t, client, firstUser.OrganizationID,
1188 rbac.ScopedRoleAgentsAccess(firstUser.OrganizationID),
1189 rbac.ScopedRoleAgentsAccess(secondOrg.ID),
1190 )
1191 memberExp := codersdk.NewExperimentalClient(memberClientRaw)
1192 // Member creates a chat in the second org.
1193 memberChat, err := memberExp.CreateChat(ctx, codersdk.CreateChatRequest{
1194 OrganizationID: secondOrg.ID,
1195 Content: []codersdk.ChatInputPart{
1196 {
1197 Type: codersdk.ChatInputPartTypeText,
1198 Text: "hello from member",
1199 },
1200 },
1201 })
1202 require.NoError(t, err)
1203 require.Equal(t, secondOrg.ID, memberChat.OrganizationID)
1204
1205 // Create an org admin in the second org with agents access.
1206 adminClientRaw, _ := coderdtest.CreateAnotherUser(
1207 t, client, firstUser.OrganizationID,

Callers

nothing calls this directly

Calls 14

CreateChatModelConfigMethod · 0.95
CreateChatMethod · 0.95
ListChatsMethod · 0.95
ContextFunction · 0.92
NewFunction · 0.92
DeploymentValuesFunction · 0.92
NewExperimentalClientFunction · 0.92
RefFunction · 0.92
CreateOrganizationFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleAgentsAccessFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92

Tested by

no test coverage detected