| 908 | } |
| 909 | |
| 910 | func TestChat_AllFieldsPopulated(t *testing.T) { |
| 911 | t.Parallel() |
| 912 | |
| 913 | // Every field of database.Chat is set to a non-zero value so |
| 914 | // that the reflection check below catches any field that |
| 915 | // db2sdk.Chat forgets to populate. When someone adds a new |
| 916 | // field to codersdk.Chat, this test will fail until the |
| 917 | // converter is updated. |
| 918 | now := dbtime.Now() |
| 919 | lastErrorPayload := codersdk.ChatError{ |
| 920 | Message: "boom", |
| 921 | Detail: "provider detail", |
| 922 | Kind: codersdk.ChatErrorKindGeneric, |
| 923 | Provider: "openai", |
| 924 | Retryable: true, |
| 925 | StatusCode: 503, |
| 926 | } |
| 927 | lastErrorRaw, err := json.Marshal(lastErrorPayload) |
| 928 | require.NoError(t, err) |
| 929 | |
| 930 | input := database.Chat{ |
| 931 | ID: uuid.New(), |
| 932 | OwnerID: uuid.New(), |
| 933 | OwnerUsername: "owner-username", |
| 934 | OwnerName: "Owner Name", |
| 935 | OrganizationID: uuid.New(), |
| 936 | WorkspaceID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, |
| 937 | BuildID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, |
| 938 | AgentID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, |
| 939 | ParentChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, |
| 940 | RootChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true}, |
| 941 | LastModelConfigID: uuid.New(), |
| 942 | Title: "all-fields-test", |
| 943 | Status: database.ChatStatusRunning, |
| 944 | ClientType: database.ChatClientTypeUi, |
| 945 | LastError: pqtype.NullRawMessage{RawMessage: lastErrorRaw, Valid: true}, |
| 946 | LastTurnSummary: sql.NullString{String: "turn completed", Valid: true}, |
| 947 | CreatedAt: now, |
| 948 | UpdatedAt: now, |
| 949 | Archived: true, |
| 950 | PinOrder: 1, |
| 951 | PlanMode: database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true}, |
| 952 | MCPServerIDs: []uuid.UUID{uuid.New()}, |
| 953 | Labels: database.StringMap{"env": "prod"}, |
| 954 | LastInjectedContext: pqtype.NullRawMessage{ |
| 955 | // Use a context-file part to verify internal |
| 956 | // fields are not present (they are stripped at |
| 957 | // write time by chatd, not at read time). |
| 958 | RawMessage: json.RawMessage(`[{"type":"context-file","context_file_path":"/AGENTS.md"}]`), |
| 959 | Valid: true, |
| 960 | }, |
| 961 | DynamicTools: pqtype.NullRawMessage{ |
| 962 | RawMessage: json.RawMessage(`[{"name":"tool1","description":"test tool","inputSchema":{"type":"object"}}]`), |
| 963 | Valid: true, |
| 964 | }, |
| 965 | } |
| 966 | // Only ChatID is needed here. This test checks that |
| 967 | // Chat.DiffStatus is non-nil, not that every DiffStatus |