(t *testing.T)
| 1880 | } |
| 1881 | |
| 1882 | func TestTasksNotification(t *testing.T) { |
| 1883 | t.Parallel() |
| 1884 | |
| 1885 | for _, tc := range []struct { |
| 1886 | name string |
| 1887 | latestAppStatuses []codersdk.WorkspaceAppStatusState |
| 1888 | newAppStatus codersdk.WorkspaceAppStatusState |
| 1889 | isAITask bool |
| 1890 | isNotificationSent bool |
| 1891 | notificationTemplate uuid.UUID |
| 1892 | taskPrompt string |
| 1893 | agentLifecycle database.WorkspaceAgentLifecycleState |
| 1894 | }{ |
| 1895 | // Should not send a notification when the agent app is not an AI task. |
| 1896 | { |
| 1897 | name: "NoAITask", |
| 1898 | latestAppStatuses: nil, |
| 1899 | newAppStatus: codersdk.WorkspaceAppStatusStateWorking, |
| 1900 | isAITask: false, |
| 1901 | isNotificationSent: false, |
| 1902 | taskPrompt: "NoAITask", |
| 1903 | }, |
| 1904 | // Should not send a notification when the new app status is neither 'Working' nor 'Idle'. |
| 1905 | { |
| 1906 | name: "NonNotifiedState", |
| 1907 | latestAppStatuses: nil, |
| 1908 | newAppStatus: codersdk.WorkspaceAppStatusStateComplete, |
| 1909 | isAITask: true, |
| 1910 | isNotificationSent: false, |
| 1911 | taskPrompt: "NonNotifiedState", |
| 1912 | }, |
| 1913 | // Should not send a notification when the new app status equals the latest status (Working). |
| 1914 | { |
| 1915 | name: "NonNotifiedTransition", |
| 1916 | latestAppStatuses: []codersdk.WorkspaceAppStatusState{codersdk.WorkspaceAppStatusStateWorking}, |
| 1917 | newAppStatus: codersdk.WorkspaceAppStatusStateWorking, |
| 1918 | isAITask: true, |
| 1919 | isNotificationSent: false, |
| 1920 | taskPrompt: "NonNotifiedTransition", |
| 1921 | }, |
| 1922 | // Should NOT send TemplateTaskWorking when the AI task's FIRST status is 'Working' (obvious state). |
| 1923 | { |
| 1924 | name: "TemplateTaskWorking", |
| 1925 | latestAppStatuses: nil, |
| 1926 | newAppStatus: codersdk.WorkspaceAppStatusStateWorking, |
| 1927 | isAITask: true, |
| 1928 | isNotificationSent: false, |
| 1929 | notificationTemplate: notifications.TemplateTaskWorking, |
| 1930 | taskPrompt: "TemplateTaskWorking", |
| 1931 | }, |
| 1932 | // Should send TemplateTaskIdle when the AI task's FIRST status is 'Idle' (task completed immediately). |
| 1933 | { |
| 1934 | name: "InitialTemplateTaskIdle", |
| 1935 | latestAppStatuses: nil, |
| 1936 | newAppStatus: codersdk.WorkspaceAppStatusStateIdle, |
| 1937 | isAITask: true, |
| 1938 | isNotificationSent: true, |
| 1939 | notificationTemplate: notifications.TemplateTaskIdle, |
nothing calls this directly
no test coverage detected