|
203 | 203 | (lambda (&rest _args) "TDD Red + Green + Blue (refactor after Green)"))) |
204 | 204 | (should (eq 'tdd-with-refactoring (ai-code--read-auto-test-type-choice)))))) |
205 | 205 |
|
| 206 | +(ert-deftest ai-code-test-read-auto-follow-up-choice-uses-y-or-n-p () |
| 207 | + "Test that follow-up choice reads a y/n decision." |
| 208 | + (let ((asked-prompt nil)) |
| 209 | + (cl-letf (((symbol-function 'y-or-n-p) |
| 210 | + (lambda (prompt) |
| 211 | + (setq asked-prompt prompt) |
| 212 | + t)) |
| 213 | + ((symbol-function 'completing-read) |
| 214 | + (lambda (&rest _args) |
| 215 | + (ert-fail "Should not use completing-read for follow-up y/n choice.")))) |
| 216 | + (should (eq t (ai-code--read-auto-follow-up-choice))) |
| 217 | + (should (string-match-p |
| 218 | + "\\`Discussion follow-up suggestions\\(?: (y/n)\\)?\\? \\'" |
| 219 | + asked-prompt))))) |
| 220 | + |
206 | 221 | (ert-deftest ai-code-test-resolve-auto-follow-up-suffix-for-send-off () |
207 | 222 | "Test that off mode never resolves a discussion follow-up suffix." |
208 | 223 | (let ((ai-code-discussion-auto-follow-up-enabled nil) |
|
217 | 232 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
218 | 233 | (lambda (_prompt-text) 'non-code-change)) |
219 | 234 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
220 | | - (lambda () t))) |
| 235 | + (lambda (&rest _args) t))) |
221 | 236 | (should (string-match-p |
222 | 237 | "3-4 numbered candidate next[[:space:]\n]+steps" |
223 | 238 | (ai-code--resolve-auto-follow-up-suffix-for-send |
224 | 239 | "Explain this function"))) |
225 | 240 | (should (string-match-p |
226 | 241 | "At least 2 candidates must[[:space:]\n]+be AI-actionable items" |
227 | | - (ai-code--resolve-auto-follow-up-suffix-for-send |
228 | | - "Explain this function")))))) |
| 242 | + (ai-code--resolve-auto-follow-up-suffix-for-send |
| 243 | + "Explain this function")))))) |
| 244 | + |
| 245 | +(ert-deftest ai-code-test-resolve-auto-follow-up-suffix-calls-choice-reader-without-args () |
| 246 | + "Test that follow-up choice reader is called without extra arguments." |
| 247 | + (let ((ai-code-discussion-auto-follow-up-enabled t) |
| 248 | + (ai-code-next-step-suggestion-suffix "FOLLOW-UP") |
| 249 | + (ai-code-use-gptel-classify-prompt nil)) |
| 250 | + (cl-letf (((symbol-function 'ai-code--read-auto-follow-up-choice) |
| 251 | + (lambda () t))) |
| 252 | + (should (equal "FOLLOW-UP" |
| 253 | + (ai-code--resolve-auto-follow-up-suffix-for-send |
| 254 | + "Explain this function")))))) |
229 | 255 |
|
230 | 256 | (ert-deftest ai-code-test-resolve-auto-follow-up-suffix-for-send-ask-me-code-change-skips () |
231 | 257 | "Test that ask-me mode does not offer next-step suggestions for code-change prompts." |
|
236 | 262 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
237 | 263 | (lambda (_prompt-text) 'code-change)) |
238 | 264 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
239 | | - (lambda () |
| 265 | + (lambda (&rest _args) |
240 | 266 | (setq asked t) |
241 | 267 | t))) |
242 | 268 | (should-not |
|
253 | 279 | (lambda (_prompt-text) |
254 | 280 | (ert-fail "Should not call GPTel for code-change prompt markers."))) |
255 | 281 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
256 | | - (lambda () |
| 282 | + (lambda (&rest _args) |
257 | 283 | (setq asked t) |
258 | 284 | t))) |
259 | 285 | (should-not |
|
268 | 294 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
269 | 295 | (lambda (_prompt-text) 'non-code-change)) |
270 | 296 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
271 | | - (lambda () t))) |
| 297 | + (lambda (&rest _args) t))) |
272 | 298 | (let ((this-command 'ai-code-ask-question)) |
273 | 299 | (should (string-match-p |
274 | 300 | "The user may also[[:space:]\n]+ignore these options" |
|
291 | 317 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
292 | 318 | (lambda (_prompt-text) 'non-code-change)) |
293 | 319 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
294 | | - (lambda () t)) |
| 320 | + (lambda (&rest _args) t)) |
295 | 321 | ((symbol-function 'ai-code--get-ai-code-prompt-file-path) |
296 | 322 | (lambda () nil)) |
297 | 323 | ((symbol-function 'ai-code-cli-send-command) |
|
322 | 348 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
323 | 349 | (lambda (_prompt-text) 'non-code-change)) |
324 | 350 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
325 | | - (lambda () t)) |
| 351 | + (lambda (&rest _args) t)) |
326 | 352 | ((symbol-function 'ai-code--get-ai-code-prompt-file-path) |
327 | 353 | (lambda () prompt-file)) |
328 | 354 | ((symbol-function 'ai-code-cli-send-command) |
|
352 | 378 | (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
353 | 379 | (lambda (_prompt-text) 'non-code-change)) |
354 | 380 | ((symbol-function 'ai-code--read-auto-follow-up-choice) |
355 | | - (lambda () t)) |
| 381 | + (lambda (&rest _args) t)) |
356 | 382 | ((symbol-function 'ai-code--get-ai-code-prompt-file-path) |
357 | 383 | (lambda () nil)) |
358 | 384 | ((symbol-function 'ai-code-cli-send-command) |
|
495 | 521 | 'boolean |
496 | 522 | (get 'ai-code-discussion-auto-follow-up-enabled 'custom-type)))) |
497 | 523 |
|
| 524 | +(ert-deftest ai-code-test-discussion-auto-follow-up-enabled-default-is-on () |
| 525 | + "Test that discussion auto follow-up defaults to enabled." |
| 526 | + (should (eq t (default-value 'ai-code-discussion-auto-follow-up-enabled)))) |
| 527 | + |
498 | 528 | (ert-deftest ai-code-test-resolve-auto-test-suffix-for-send-ask-me-tdd-with-refactoring () |
499 | 529 | "Test that ask-me resolves to the repo-local TDD harness reference." |
500 | 530 | (let* ((temp-root (make-temp-file "ai-code-harness-root-" t)) |
|
528 | 558 | "Test that ask-me no-test choice appends explicit no-test instruction." |
529 | 559 | (let ((sent-command nil) |
530 | 560 | (ai-code-auto-test-type 'ask-me) |
| 561 | + (ai-code-discussion-auto-follow-up-enabled nil) |
531 | 562 | (ai-code-use-prompt-suffix t) |
532 | 563 | (ai-code-prompt-suffix "BASE SUFFIX") |
533 | 564 | (ai-code-auto-test-suffix "SHOULD NOT APPEAR")) |
|
0 commit comments