| 173 | } |
| 174 | |
| 175 | func Test_buildManualTitleContext(t *testing.T) { |
| 176 | t.Parallel() |
| 177 | |
| 178 | longConversationText := strings.Repeat("a", 3500) |
| 179 | longLatestUserText := strings.Repeat("z", 1200) |
| 180 | |
| 181 | tests := []struct { |
| 182 | name string |
| 183 | turns []manualTitleTurn |
| 184 | selected []int |
| 185 | wantConversation string |
| 186 | wantConversationEmpty bool |
| 187 | wantConversationHasGap bool |
| 188 | wantConversationRunes int |
| 189 | wantLatestUser string |
| 190 | wantLatestUserRunes int |
| 191 | wantLatestUserContains string |
| 192 | wantLatestUserNotEmpty bool |
| 193 | }{ |
| 194 | { |
| 195 | name: "adds gap marker when selected turns skip earlier context", |
| 196 | turns: []manualTitleTurn{ |
| 197 | {role: "user", text: "open pull request"}, |
| 198 | {role: "assistant", text: "checked CI"}, |
| 199 | {role: "user", text: "review logs"}, |
| 200 | {role: "assistant", text: "found flaky test"}, |
| 201 | {role: "user", text: "update chat title"}, |
| 202 | }, |
| 203 | selected: []int{0, 3, 4}, |
| 204 | wantConversationHasGap: true, |
| 205 | wantLatestUser: "update chat title", |
| 206 | }, |
| 207 | { |
| 208 | name: "omits gap marker for contiguous selection", |
| 209 | turns: []manualTitleTurn{ |
| 210 | {role: "user", text: "open pull request"}, |
| 211 | {role: "assistant", text: "checked CI"}, |
| 212 | {role: "user", text: "update chat title"}, |
| 213 | }, |
| 214 | selected: []int{0, 1, 2}, |
| 215 | wantConversation: "[user]: open pull request\n[assistant]: checked CI\n[user]: update chat title", |
| 216 | wantConversationHasGap: false, |
| 217 | wantLatestUser: "update chat title", |
| 218 | }, |
| 219 | { |
| 220 | name: "single useful user turn returns empty conversation block", |
| 221 | turns: []manualTitleTurn{{role: "user", text: "rename helper"}}, |
| 222 | selected: []int{0}, |
| 223 | wantConversationEmpty: true, |
| 224 | wantLatestUser: "rename helper", |
| 225 | }, |
| 226 | { |
| 227 | name: "truncates conversation block at six thousand runes", |
| 228 | turns: []manualTitleTurn{ |
| 229 | {role: "user", text: longConversationText}, |
| 230 | {role: "assistant", text: longConversationText}, |
| 231 | {role: "user", text: "latest"}, |
| 232 | }, |