MCPcopy Index your code
hub / github.com/coder/coder / TestListChatsExcludesSharedChats

Function TestListChatsExcludesSharedChats

coderd/exp_chats_acl_test.go:371–403  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

369}
370
371func TestListChatsExcludesSharedChats(t *testing.T) {
372 t.Parallel()
373
374 ctx := testutil.Context(t, testutil.WaitLong)
375 client, db := newChatClientWithDatabase(t)
376 firstUser := coderdtest.CreateFirstUser(t, client.Client)
377 modelConfig := createChatModelConfig(t, client)
378 viewerClient, viewer := coderdtest.CreateAnotherUser(t, client.Client, firstUser.OrganizationID, rbac.ScopedRoleAgentsAccess(firstUser.OrganizationID))
379 viewerClientExp := codersdk.NewExperimentalClient(viewerClient)
380 sharedChat := dbgen.Chat(t, db, database.Chat{
381 OrganizationID: firstUser.OrganizationID,
382 OwnerID: firstUser.UserID,
383 LastModelConfigID: modelConfig.ID,
384 Title: "shared with viewer",
385 })
386 viewerChat := dbgen.Chat(t, db, database.Chat{
387 OrganizationID: firstUser.OrganizationID,
388 OwnerID: viewer.ID,
389 LastModelConfigID: modelConfig.ID,
390 Title: "viewer owned",
391 })
392
393 err := client.UpdateChatACL(ctx, sharedChat.ID, codersdk.UpdateChatACL{
394 UserRoles: map[string]codersdk.ChatRole{
395 viewer.ID.String(): codersdk.ChatRoleRead,
396 },
397 })
398 require.NoError(t, err)
399
400 ownedOnly, err := viewerClientExp.ListChats(ctx, nil)
401 require.NoError(t, err)
402 require.Equal(t, map[uuid.UUID]struct{}{viewerChat.ID: {}}, chatIDSet(ownedOnly))
403}
404
405//nolint:paralleltest // This test verifies a process-wide RBAC kill switch.
406func TestChatSharingDisabled(t *testing.T) {

Callers

nothing calls this directly

Calls 13

ListChatsMethod · 0.95
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleAgentsAccessFunction · 0.92
NewExperimentalClientFunction · 0.92
ChatFunction · 0.92
chatIDSetFunction · 0.85
UpdateChatACLMethod · 0.80
createChatModelConfigFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected