|
31 | 31 |
|
32 | 32 | (defvar ai-code--tdd-run-test-after-each-stage-instruction) |
33 | 33 |
|
34 | | -(ert-deftest ai-code-test-set-auto-test-type-tdd-updates-suffix () |
35 | | - "Test that setting auto test type to tdd updates the suffix text." |
| 34 | +(ert-deftest ai-code-test-set-auto-test-type-ask-me-clears-persistent-suffix () |
| 35 | + "Test that setting auto test type to ask-me clears the persistent suffix." |
36 | 36 | (let ((ai-code-auto-test-suffix "old") |
37 | 37 | (ai-code-auto-test-type nil) |
38 | 38 | (ai-code--tdd-test-pattern-instruction nil)) |
39 | | - (ai-code--apply-auto-test-type 'tdd) |
40 | | - (should (string-match-p "Stage 1 - Red" ai-code-auto-test-suffix)) |
41 | | - (should (string-match-p "Stage 2 - Green" ai-code-auto-test-suffix)))) |
| 39 | + (ai-code--apply-auto-test-type 'ask-me) |
| 40 | + (should (eq 'ask-me ai-code-auto-test-type)) |
| 41 | + (should-not ai-code-auto-test-suffix))) |
42 | 42 |
|
43 | | -(ert-deftest ai-code-test-set-auto-test-type-tdd-with-refactoring-updates-suffix () |
44 | | - "Test that setting auto test type to tdd-with-refactoring updates suffix text." |
| 43 | +(ert-deftest ai-code-test-set-auto-test-type-off-clears-persistent-suffix () |
| 44 | + "Test that turning off auto test type clears the persistent suffix." |
45 | 45 | (let ((ai-code-auto-test-suffix "old") |
46 | | - (ai-code-auto-test-type nil) |
47 | | - (ai-code--tdd-test-pattern-instruction "")) |
48 | | - (ai-code--apply-auto-test-type 'tdd-with-refactoring) |
49 | | - (should (string-match-p |
50 | | - (regexp-quote ai-code--tdd-with-refactoring-extension-instruction) |
51 | | - ai-code-auto-test-suffix)) |
52 | | - (should (string-match-p "Stage 3 - Blue" ai-code-auto-test-suffix)) |
53 | | - (should (string-match-p "highest-impact cleanup" ai-code-auto-test-suffix)))) |
| 46 | + (ai-code-auto-test-type 'ask-me)) |
| 47 | + (ai-code--apply-auto-test-type nil) |
| 48 | + (should-not ai-code-auto-test-type) |
| 49 | + (should-not ai-code-auto-test-suffix))) |
54 | 50 |
|
55 | 51 | (ert-deftest ai-code-test-resolve-tdd-suffix-includes-strict-stage-contract () |
56 | 52 | "Test that TDD suffix names Red and Green stages and forbids skipping." |
|
69 | 65 | (should (string-match-p "SHARED_EACH_STAGE_TEST_INSTRUCTION" |
70 | 66 | (ai-code--test-after-code-change--resolve-tdd-suffix))))) |
71 | 67 |
|
72 | | -(ert-deftest ai-code-test-resolve-auto-test-type-for-send () |
73 | | - "Test that send-time type resolution is consistent across mode values." |
74 | | - (let ((ai-code-auto-test-type 'test-after-change)) |
75 | | - (should (eq 'test-after-change (ai-code--resolve-auto-test-type-for-send)))) |
76 | | - (let ((ai-code-auto-test-type 'tdd)) |
77 | | - (should (eq 'tdd (ai-code--resolve-auto-test-type-for-send)))) |
78 | | - (let ((ai-code-auto-test-type 'tdd-with-refactoring)) |
79 | | - (should (eq 'tdd-with-refactoring (ai-code--resolve-auto-test-type-for-send)))) |
| 68 | +(ert-deftest ai-code-test-resolve-auto-test-type-for-send-off () |
| 69 | + "Test that off mode never resolves a send-time auto test type." |
80 | 70 | (let ((ai-code-auto-test-type nil)) |
81 | | - (should (eq nil (ai-code--resolve-auto-test-type-for-send))))) |
| 71 | + (should-not (ai-code--resolve-auto-test-type-for-send)))) |
| 72 | + |
| 73 | +(ert-deftest ai-code-test-resolve-auto-test-type-for-send-legacy-persistent-modes () |
| 74 | + "Test that legacy persistent auto test modes still resolve at send time." |
| 75 | + (dolist (mode '(test-after-change tdd tdd-with-refactoring)) |
| 76 | + (let ((ai-code-auto-test-type mode)) |
| 77 | + (should (eq mode |
| 78 | + (ai-code--resolve-auto-test-type-for-send)))))) |
82 | 79 |
|
83 | 80 | (ert-deftest ai-code-test-resolve-auto-test-type-for-send-ask-me () |
84 | 81 | "Test that ask-me mode resolves by interactive per-send selection." |
|
119 | 116 | (should (eq 'test-after-change |
120 | 117 | (ai-code--resolve-auto-test-type-for-send "Please update code")))))) |
121 | 118 |
|
122 | | -(ert-deftest ai-code-test-resolve-auto-test-type-for-send-fixed-type-gptel-classification-test-after-change () |
123 | | - "Test that test-after-change mode appends suffix only for GPTel code-change classification." |
124 | | - (let ((ai-code-auto-test-type 'test-after-change) |
125 | | - (ai-code-use-gptel-classify-prompt t)) |
126 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
127 | | - (lambda (_prompt-text) 'code-change))) |
128 | | - (should (eq 'test-after-change |
129 | | - (ai-code--resolve-auto-test-type-for-send "Refactor this code")))) |
130 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
131 | | - (lambda (_prompt-text) 'non-code-change))) |
132 | | - (should (eq nil |
133 | | - (ai-code--resolve-auto-test-type-for-send "Explain this design")))) |
134 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
135 | | - (lambda (_prompt-text) 'unknown))) |
136 | | - (should (eq nil |
137 | | - (ai-code--resolve-auto-test-type-for-send "Do something")))))) |
138 | | - |
139 | | -(ert-deftest ai-code-test-resolve-auto-test-type-for-send-fixed-type-gptel-classification-tdd () |
140 | | - "Test that tdd mode appends suffix only for GPTel code-change classification." |
141 | | - (let ((ai-code-auto-test-type 'tdd) |
142 | | - (ai-code-use-gptel-classify-prompt t)) |
143 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
144 | | - (lambda (_prompt-text) 'code-change))) |
145 | | - (should (eq 'tdd |
146 | | - (ai-code--resolve-auto-test-type-for-send "Implement feature")))) |
147 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
148 | | - (lambda (_prompt-text) 'non-code-change))) |
149 | | - (should (eq nil |
150 | | - (ai-code--resolve-auto-test-type-for-send "Summarize this file")))) |
151 | | - (cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change) |
152 | | - (lambda (_prompt-text) 'unknown))) |
153 | | - (should (eq nil |
154 | | - (ai-code--resolve-auto-test-type-for-send "Review architecture")))))) |
155 | | - |
156 | 119 | (ert-deftest ai-code-test-read-auto-test-type-choice-allow-no-test () |
157 | 120 | "Test that ask choices support selecting no test run." |
158 | 121 | (let ((ai-code--auto-test-type-ask-choices |
|
186 | 149 | (should-not (assoc "Test driven development, follow up with refactoring" |
187 | 150 | ai-code--auto-test-type-ask-choices))) |
188 | 151 |
|
| 152 | +(ert-deftest ai-code-test-auto-test-type-custom-options-are-ask-or-off () |
| 153 | + "Test that persistent auto test type choices only expose ask-me and off." |
| 154 | + (should |
| 155 | + (equal |
| 156 | + '(choice (const :tag "Ask every time" ask-me) |
| 157 | + (const :tag "Off" nil)) |
| 158 | + (get 'ai-code-auto-test-type 'custom-type)))) |
| 159 | + |
| 160 | +(ert-deftest ai-code-test-auto-test-type-persistent-choices-are-ask-or-off () |
| 161 | + "Test that persistent auto test type choices are shared and limited." |
| 162 | + (should (equal '(("Ask every time" . ask-me) |
| 163 | + ("Off" . nil)) |
| 164 | + ai-code--auto-test-type-persistent-choices))) |
| 165 | + |
189 | 166 | (ert-deftest ai-code-test-resolve-auto-test-suffix-for-send-ask-me-tdd-with-refactoring () |
190 | 167 | "Test that ask-me can resolve to refactoring TDD suffix." |
191 | 168 | (let ((ai-code-auto-test-type 'ask-me) |
|
0 commit comments