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

Function TestGetAuthorizedChatsACLSharing

coderd/database/querier_test.go:1486–1591  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // It toggles the global chat ACL flag.

(t *testing.T)

Source from the content-addressed store, hash-verified

1484
1485//nolint:tparallel,paralleltest // It toggles the global chat ACL flag.
1486func TestGetAuthorizedChatsACLSharing(t *testing.T) {
1487 if testing.Short() {
1488 t.SkipNow()
1489 }
1490
1491 rbac.SetChatACLDisabled(false)
1492 t.Cleanup(func() { rbac.SetChatACLDisabled(false) })
1493
1494 ctx := testutil.Context(t, testutil.WaitMedium)
1495 sqlDB := testSQLDB(t)
1496 err := migrations.Up(sqlDB)
1497 require.NoError(t, err)
1498 db := database.New(sqlDB)
1499 authorizer := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry())
1500
1501 owner := dbgen.User(t, db, database.User{})
1502 recipient := dbgen.User(t, db, database.User{})
1503 org := dbgen.Organization(t, db, database.Organization{})
1504 dbgen.OrganizationMember(t, db, database.OrganizationMember{
1505 UserID: owner.ID,
1506 OrganizationID: org.ID,
1507 Roles: []string{rbac.RoleAgentsAccess()},
1508 })
1509 dbgen.OrganizationMember(t, db, database.OrganizationMember{
1510 UserID: recipient.ID,
1511 OrganizationID: org.ID,
1512 Roles: []string{rbac.RoleAgentsAccess()},
1513 })
1514
1515 dbgen.ChatProvider(t, db, database.ChatProvider{Provider: "openai", DisplayName: "OpenAI"})
1516 modelCfg := dbgen.ChatModelConfig(t, db, database.ChatModelConfig{
1517 Provider: "openai",
1518 Model: "test-model",
1519 CreatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
1520 UpdatedBy: uuid.NullUUID{UUID: owner.ID, Valid: true},
1521 IsDefault: true,
1522 CompressionThreshold: 80,
1523 })
1524
1525 ownerChat := dbgen.Chat(t, db, database.Chat{
1526 OrganizationID: org.ID,
1527 OwnerID: owner.ID,
1528 LastModelConfigID: modelCfg.ID,
1529 Title: "shared owner chat",
1530 })
1531 recipientChat := dbgen.Chat(t, db, database.Chat{
1532 OrganizationID: org.ID,
1533 OwnerID: recipient.ID,
1534 LastModelConfigID: modelCfg.ID,
1535 Title: "recipient chat",
1536 })
1537
1538 sharedACL := database.ChatACL{
1539 recipient.ID.String(): database.ChatACLEntry{Permissions: []policy.Action{policy.ActionRead}},
1540 }
1541 err = db.UpdateChatACLByID(ctx, database.UpdateChatACLByIDParams{
1542 ID: ownerChat.ID,
1543 UserACL: sharedACL,

Callers

nothing calls this directly

Calls 15

SetChatACLDisabledFunction · 0.92
ContextFunction · 0.92
UpFunction · 0.92
NewFunction · 0.92
UserFunction · 0.92
OrganizationFunction · 0.92
OrganizationMemberFunction · 0.92
RoleAgentsAccessFunction · 0.92
ChatProviderFunction · 0.92
ChatModelConfigFunction · 0.92
ChatFunction · 0.92

Tested by

no test coverage detected