(t *testing.T)
| 1078 | } |
| 1079 | |
| 1080 | func TestCreateChatNonDefaultOrg(t *testing.T) { |
| 1081 | t.Parallel() |
| 1082 | |
| 1083 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1084 | |
| 1085 | client, firstUser := coderdenttest.New(t, &coderdenttest.Options{ |
| 1086 | Options: &coderdtest.Options{ |
| 1087 | DeploymentValues: func() *codersdk.DeploymentValues { |
| 1088 | v := coderdtest.DeploymentValues(t) |
| 1089 | return v |
| 1090 | }(), |
| 1091 | }, |
| 1092 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 1093 | Features: license.Features{ |
| 1094 | codersdk.FeatureMultipleOrganizations: 1, |
| 1095 | }, |
| 1096 | }, |
| 1097 | }) |
| 1098 | expClient := codersdk.NewExperimentalClient(client) |
| 1099 | |
| 1100 | provider := createOpenAIProviderForTest(ctx, t, expClient, "test-key", "https://example.com") |
| 1101 | _, err := expClient.CreateChatModelConfig(ctx, codersdk.CreateChatModelConfigRequest{ |
| 1102 | Provider: string(provider.Type), |
| 1103 | AIProviderID: &provider.ID, |
| 1104 | Model: "gpt-4o-mini", |
| 1105 | DisplayName: "Test Model", |
| 1106 | IsDefault: ptr.Ref(true), |
| 1107 | ContextLimit: ptr.Ref(int64(1000)), |
| 1108 | CompressionThreshold: ptr.Ref(int32(70)), |
| 1109 | }) |
| 1110 | require.NoError(t, err) |
| 1111 | |
| 1112 | // Create a second (non-default) org via the API. |
| 1113 | secondOrg := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{}) |
| 1114 | |
| 1115 | // Create a member with agents-access in both orgs. |
| 1116 | memberClientRaw, member := coderdtest.CreateAnotherUser( |
| 1117 | t, client, firstUser.OrganizationID, |
| 1118 | rbac.ScopedRoleAgentsAccess(firstUser.OrganizationID), |
| 1119 | rbac.ScopedRoleAgentsAccess(secondOrg.ID), |
| 1120 | ) |
| 1121 | memberClient := codersdk.NewExperimentalClient(memberClientRaw) |
| 1122 | // Create a chat in the non-default org. |
| 1123 | chat, err := memberClient.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 1124 | OrganizationID: secondOrg.ID, |
| 1125 | Content: []codersdk.ChatInputPart{ |
| 1126 | { |
| 1127 | Type: codersdk.ChatInputPartTypeText, |
| 1128 | Text: "hello from non-default org", |
| 1129 | }, |
| 1130 | }, |
| 1131 | }) |
| 1132 | require.NoError(t, err) |
| 1133 | require.Equal(t, secondOrg.ID, chat.OrganizationID) |
| 1134 | require.Equal(t, member.ID, chat.OwnerID) |
| 1135 | |
| 1136 | // Verify the chat is visible when listing. |
| 1137 | chats, err := memberClient.ListChats(ctx, nil) |
nothing calls this directly
no test coverage detected