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

Function TestGetChatDiffContents

coderd/exp_chats_test.go:8805–8911  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8803}
8804
8805func TestGetChatDiffContents(t *testing.T) {
8806 t.Parallel()
8807
8808 t.Run("SuccessWithCachedRepositoryReference", func(t *testing.T) {
8809 t.Parallel()
8810
8811 ctx := testutil.Context(t, testutil.WaitLong)
8812 rawClient, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
8813 DeploymentValues: chatDeploymentValues(t),
8814 ExternalAuthConfigs: []*externalauth.Config{
8815 {
8816 ID: "gitlab-test",
8817 Type: "gitlab",
8818 Regex: regexp.MustCompile(`gitlab\.example\.com`),
8819 },
8820 },
8821 })
8822 client := codersdk.NewExperimentalClient(rawClient)
8823 db := api.Database
8824 user := coderdtest.CreateFirstUser(t, client.Client)
8825 modelConfig := createChatModelConfig(t, client)
8826 chat := dbgen.Chat(t, db, database.Chat{
8827 OrganizationID: user.OrganizationID,
8828 OwnerID: user.UserID,
8829 LastModelConfigID: modelConfig.ID,
8830 Title: "diff contents with cached repository reference",
8831 })
8832
8833 _, err := db.UpsertChatDiffStatusReference(
8834 dbauthz.AsSystemRestricted(ctx),
8835 database.UpsertChatDiffStatusReferenceParams{
8836 ChatID: chat.ID,
8837 Url: sql.NullString{},
8838 GitBranch: "feature/cached-diff",
8839 GitRemoteOrigin: "https://gitlab.example.com/acme/project.git",
8840 StaleAt: time.Now().UTC().Add(time.Hour),
8841 },
8842 )
8843 require.NoError(t, err)
8844
8845 diffContents, err := client.GetChatDiffContents(ctx, chat.ID)
8846 require.NoError(t, err)
8847 require.Equal(t, chat.ID, diffContents.ChatID)
8848 require.NotNil(t, diffContents.Provider)
8849 require.Equal(t, "gitlab", *diffContents.Provider)
8850 require.NotNil(t, diffContents.RemoteOrigin)
8851 require.Equal(t, "https://gitlab.example.com/acme/project.git", *diffContents.RemoteOrigin)
8852 require.NotNil(t, diffContents.Branch)
8853 require.Equal(t, "feature/cached-diff", *diffContents.Branch)
8854 require.Nil(t, diffContents.PullRequestURL)
8855 require.Empty(t, diffContents.Diff)
8856 })
8857
8858 t.Run("SuccessWithoutCachedReference", func(t *testing.T) {
8859 t.Parallel()
8860
8861 ctx := testutil.Context(t, testutil.WaitLong)
8862 client := newChatClient(t)

Callers

nothing calls this directly

Calls 15

GetChatDiffContentsMethod · 0.95
CreateChatMethod · 0.95
ContextFunction · 0.92
NewWithAPIFunction · 0.92
NewExperimentalClientFunction · 0.92
CreateFirstUserFunction · 0.92
ChatFunction · 0.92
AsSystemRestrictedFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleAgentsAccessFunction · 0.92
chatDeploymentValuesFunction · 0.85
requireSDKErrorFunction · 0.85

Tested by

no test coverage detected