|
449 | 449 | (when (file-directory-p working-dir) |
450 | 450 | (delete-directory working-dir t))))) |
451 | 451 |
|
| 452 | +(ert-deftest test-ai-code-backends-infra-create-terminal-session-eat-filter-ignores-dead-buffer () |
| 453 | + "Eat filter wrapper should skip bookkeeping when session buffer is dead." |
| 454 | + (let* ((buffer-name "*test-ai-code-eat-dead-buffer*") |
| 455 | + (buffer (get-buffer-create buffer-name)) |
| 456 | + (ai-code-backends-infra-terminal-backend 'eat) |
| 457 | + (wrapped-filter nil) |
| 458 | + (orig-filter-called nil) |
| 459 | + (strip-called nil) |
| 460 | + (note-called nil) |
| 461 | + (linkify-called nil)) |
| 462 | + (unwind-protect |
| 463 | + (progn |
| 464 | + (cl-letf (((symbol-function 'ai-code-backends-infra--terminal-ensure-backend) |
| 465 | + (lambda () nil)) |
| 466 | + ((symbol-function 'eat-mode) |
| 467 | + (lambda () nil)) |
| 468 | + ((symbol-function 'eat-exec) |
| 469 | + (lambda (&rest _args) nil)) |
| 470 | + ((symbol-function 'get-buffer-process) |
| 471 | + (lambda (_buffer) 'eat-proc)) |
| 472 | + ((symbol-function 'process-filter) |
| 473 | + (lambda (_process) |
| 474 | + (lambda (_process _output) |
| 475 | + (setq orig-filter-called t)))) |
| 476 | + ((symbol-function 'set-process-filter) |
| 477 | + (lambda (_process filter) |
| 478 | + (setq wrapped-filter filter))) |
| 479 | + ((symbol-function 'process-buffer) |
| 480 | + (lambda (_process) buffer)) |
| 481 | + ((symbol-function 'ai-code-backends-infra--strip-alternate-screen-sequences) |
| 482 | + (lambda (output) |
| 483 | + (setq strip-called t) |
| 484 | + output)) |
| 485 | + ((symbol-function 'ai-code-backends-infra--note-meaningful-output) |
| 486 | + (lambda (&rest _args) |
| 487 | + (setq note-called t))) |
| 488 | + ((symbol-function 'ai-code-session-link--linkify-recent-output) |
| 489 | + (lambda (&rest _args) |
| 490 | + (setq linkify-called t)))) |
| 491 | + (ai-code-backends-infra--create-terminal-session |
| 492 | + buffer-name |
| 493 | + default-directory |
| 494 | + "echo hi" |
| 495 | + nil)) |
| 496 | + (should wrapped-filter) |
| 497 | + (kill-buffer buffer) |
| 498 | + (should-not |
| 499 | + (condition-case nil |
| 500 | + (progn (funcall wrapped-filter 'eat-proc "src/foo.el:12\n") |
| 501 | + nil) |
| 502 | + (error t))) |
| 503 | + (should-not orig-filter-called) |
| 504 | + (should-not strip-called) |
| 505 | + (should-not note-called) |
| 506 | + (should-not linkify-called)) |
| 507 | + (when (buffer-live-p buffer) |
| 508 | + (kill-buffer buffer))))) |
| 509 | + |
452 | 510 | (ert-deftest test-ai-code-backends-infra-terminal-send-string-delegates-to-vterm-module () |
453 | 511 | "Terminal send should delegate vterm specifics to the vterm module." |
454 | 512 | (let ((buffer (generate-new-buffer " *ai-code-terminal-send-delegate*")) |
|
745 | 803 | (when (buffer-live-p buffer) |
746 | 804 | (kill-buffer buffer))))) |
747 | 805 |
|
| 806 | +(ert-deftest test-ai-code-backends-infra-create-terminal-session-ghostel-filter-ignores-dead-buffer () |
| 807 | + "Ghostel filter wrapper should skip bookkeeping when session buffer is dead." |
| 808 | + (let* ((buffer-name "*test-ai-code-ghostel-dead-buffer*") |
| 809 | + (buffer (get-buffer-create buffer-name)) |
| 810 | + (orig-filter-called nil) |
| 811 | + (note-called nil) |
| 812 | + (linkify-called nil) |
| 813 | + (wrapped-filter nil) |
| 814 | + (ai-code-backends-infra-terminal-backend 'ghostel)) |
| 815 | + (unwind-protect |
| 816 | + (progn |
| 817 | + (cl-letf (((symbol-function 'ai-code-backends-infra--terminal-ensure-backend) |
| 818 | + (lambda () nil)) |
| 819 | + ((symbol-function 'ghostel-exec) |
| 820 | + (lambda (target-buffer _program &optional _args) |
| 821 | + (with-current-buffer target-buffer |
| 822 | + (setq-local ghostel--process 'ghostel-proc)) |
| 823 | + 'ghostel-proc)) |
| 824 | + ((symbol-function 'get-buffer-process) |
| 825 | + (lambda (target-buffer) |
| 826 | + (with-current-buffer target-buffer |
| 827 | + ghostel--process))) |
| 828 | + ((symbol-function 'process-filter) |
| 829 | + (lambda (_process) |
| 830 | + (lambda (_process _output) |
| 831 | + (setq orig-filter-called t)))) |
| 832 | + ((symbol-function 'set-process-filter) |
| 833 | + (lambda (_process filter) |
| 834 | + (setq wrapped-filter filter))) |
| 835 | + ((symbol-function 'processp) |
| 836 | + (lambda (proc) |
| 837 | + (eq proc 'ghostel-proc))) |
| 838 | + ((symbol-function 'process-buffer) |
| 839 | + (lambda (_process) buffer)) |
| 840 | + ((symbol-function 'ai-code-backends-infra--note-meaningful-output) |
| 841 | + (lambda (&rest _args) |
| 842 | + (setq note-called t))) |
| 843 | + ((symbol-function 'ai-code-session-link--linkify-recent-output) |
| 844 | + (lambda (&rest _args) |
| 845 | + (setq linkify-called t)))) |
| 846 | + (ai-code-backends-infra--create-terminal-session |
| 847 | + buffer-name |
| 848 | + default-directory |
| 849 | + "echo hi" |
| 850 | + nil)) |
| 851 | + (should wrapped-filter) |
| 852 | + (kill-buffer buffer) |
| 853 | + (should-not |
| 854 | + (condition-case nil |
| 855 | + (progn (funcall wrapped-filter 'ghostel-proc "src/foo.el:12\n") |
| 856 | + nil) |
| 857 | + (error t))) |
| 858 | + (should-not orig-filter-called) |
| 859 | + (should-not note-called) |
| 860 | + (should-not linkify-called)) |
| 861 | + (when (buffer-live-p buffer) |
| 862 | + (kill-buffer buffer))))) |
| 863 | + |
748 | 864 | (ert-deftest test-ai-code-backends-infra-source-comment-uses-repo-stable-rationale () |
749 | 865 | "Source comments should avoid local paths and chat transcripts." |
750 | 866 | (let ((comment-found nil)) |
|
0 commit comments