Skip to content

Commit 8a5c944

Browse files
committed
fix: remove legacy prompt suffix advice on reload
1 parent db9f837 commit 8a5c944

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

ai-code-grill.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ acting."
8888
(add-hook 'ai-code-prompt-suffix-functions
8989
#'ai-code--grill-me-suffix-provider 20)
9090

91+
;; Remove the prompt-transform advice installed by pre-provider releases.
92+
(when (advice-member-p 'ai-code--with-optional-grill-me
93+
'ai-code--insert-prompt)
94+
(advice-remove 'ai-code--insert-prompt
95+
'ai-code--with-optional-grill-me))
96+
9197
(defun ai-code--install-grill-me-command-advice ()
9298
"Install origin-preserving advice on available Grill commands."
9399
(dolist (command ai-code--grill-me-commands)

ai-code-harness.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ Send-time routing uses this result for test and discussion follow-up suffixes."
456456
(add-hook 'ai-code-prompt-suffix-functions
457457
#'ai-code--discussion-follow-up-suffix-provider 40)
458458

459+
;; Remove the send-time advice installed by pre-provider releases.
460+
(when (advice-member-p 'ai-code--with-auto-test-suffix-for-send
461+
'ai-code--write-prompt-to-file-and-send)
462+
(advice-remove 'ai-code--write-prompt-to-file-and-send
463+
'ai-code--with-auto-test-suffix-for-send))
464+
459465
(defun ai-code--test-after-code-change--set (symbol value)
460466
"Set SYMBOL to VALUE and update related suffix behavior."
461467
(set-default symbol value)

test/test_ai-code-grill.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,29 @@
5454
(should (equal exit-code 0))
5555
(should-not (string-match-p "Error:" output))))
5656

57+
(ert-deftest ai-code-grill-reload-removes-legacy-prompt-advice ()
58+
"Reloading Grill should remove its legacy prompt-transform advice."
59+
(let ((was-fboundp (fboundp 'ai-code--with-optional-grill-me))
60+
(original-function
61+
(when (fboundp 'ai-code--with-optional-grill-me)
62+
(symbol-function 'ai-code--with-optional-grill-me))))
63+
(unwind-protect
64+
(progn
65+
(fset 'ai-code--with-optional-grill-me
66+
(lambda (orig-fun prompt-text)
67+
(funcall orig-fun prompt-text)))
68+
(advice-add 'ai-code--insert-prompt
69+
:around #'ai-code--with-optional-grill-me)
70+
(load (locate-library "ai-code-grill") nil nil t)
71+
(should-not
72+
(advice-member-p #'ai-code--with-optional-grill-me
73+
'ai-code--insert-prompt)))
74+
(advice-remove 'ai-code--insert-prompt
75+
#'ai-code--with-optional-grill-me)
76+
(if was-fboundp
77+
(fset 'ai-code--with-optional-grill-me original-function)
78+
(fmakunbound 'ai-code--with-optional-grill-me)))))
79+
5780
(ert-deftest ai-code-grill-disabled-keeps-prompt ()
5881
(let ((ai-code-grill-me-enabled nil)
5982
(context (ai-code-grill-test--context 'ai-code-code-change)))

test/test_ai-code-harness.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,29 @@
588588
(should (equal (ai-code--apply-prompt-suffixes "Prompt")
589589
"Prompt\nCUSTOM\nGRILL\nAUTO\nFOLLOW")))))
590590

591+
(ert-deftest ai-code-test-harness-reload-removes-legacy-send-advice ()
592+
"Reloading the harness should remove its legacy send-time advice."
593+
(let ((was-fboundp (fboundp 'ai-code--with-auto-test-suffix-for-send))
594+
(original-function
595+
(when (fboundp 'ai-code--with-auto-test-suffix-for-send)
596+
(symbol-function 'ai-code--with-auto-test-suffix-for-send))))
597+
(unwind-protect
598+
(progn
599+
(fset 'ai-code--with-auto-test-suffix-for-send
600+
(lambda (orig-fun prompt-text)
601+
(funcall orig-fun prompt-text)))
602+
(advice-add 'ai-code--write-prompt-to-file-and-send
603+
:around #'ai-code--with-auto-test-suffix-for-send)
604+
(load (locate-library "ai-code-harness") nil nil t)
605+
(should-not
606+
(advice-member-p #'ai-code--with-auto-test-suffix-for-send
607+
'ai-code--write-prompt-to-file-and-send)))
608+
(advice-remove 'ai-code--write-prompt-to-file-and-send
609+
#'ai-code--with-auto-test-suffix-for-send)
610+
(if was-fboundp
611+
(fset 'ai-code--with-auto-test-suffix-for-send original-function)
612+
(fmakunbound 'ai-code--with-auto-test-suffix-for-send)))))
613+
591614
(ert-deftest ai-code-test-use-prompt-suffix-does-not-disable-grill ()
592615
"The legacy suffix switch should not become a Grill master switch."
593616
(let ((ai-code-use-prompt-suffix nil)

0 commit comments

Comments
 (0)