|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { describe, expect, it } from "vite-plus/test"; |
2 | 2 | import * as Schema from "effect/Schema"; |
3 | 3 |
|
4 | | -import { extractXAiAskUserQuestions, XAiAskUserQuestionRequest } from "./XAiAcpExtension.ts"; |
| 4 | +import { |
| 5 | + extractXAiAskUserQuestions, |
| 6 | + makeXAiAskUserQuestionCancelledResponse, |
| 7 | + makeXAiAskUserQuestionResponse, |
| 8 | + XAiAskUserQuestionRequest, |
| 9 | +} from "./XAiAcpExtension.ts"; |
5 | 10 |
|
6 | 11 | const decodeXAiAskUserQuestionRequest = Schema.decodeUnknownSync(XAiAskUserQuestionRequest); |
7 | 12 |
|
@@ -39,7 +44,7 @@ describe("XAiAcpExtension", () => { |
39 | 44 |
|
40 | 45 | it("extracts questions from wrapped _x.ai extension payloads", () => { |
41 | 46 | const payload = { |
42 | | - method: "x.ai/ask_user_question", |
| 47 | + method: "_x.ai/ask_user_question", |
43 | 48 | params: { |
44 | 49 | sessionId: "session-1", |
45 | 50 | toolCallId: "tool-call-1", |
@@ -69,4 +74,177 @@ describe("XAiAcpExtension", () => { |
69 | 74 | }, |
70 | 75 | ]); |
71 | 76 | }); |
| 77 | + |
| 78 | + it("treats nullable multiSelect from Grok as single-select", () => { |
| 79 | + const questions = extractXAiAskUserQuestions({ |
| 80 | + sessionId: "session-1", |
| 81 | + toolCallId: "tool-call-1", |
| 82 | + mode: "default", |
| 83 | + questions: [ |
| 84 | + { |
| 85 | + question: "Which label should Grok use?", |
| 86 | + multiSelect: null, |
| 87 | + options: [ |
| 88 | + { label: "Alpha", description: "Use the Alpha label" }, |
| 89 | + { label: "Beta", description: "Use the Beta label" }, |
| 90 | + { label: "Other", description: "Use the Other label" }, |
| 91 | + ], |
| 92 | + }, |
| 93 | + ], |
| 94 | + }); |
| 95 | + |
| 96 | + expect(questions).toEqual([ |
| 97 | + { |
| 98 | + id: "Which label should Grok use?", |
| 99 | + header: "Question", |
| 100 | + question: "Which label should Grok use?", |
| 101 | + multiSelect: false, |
| 102 | + options: [ |
| 103 | + { label: "Alpha", description: "Use the Alpha label" }, |
| 104 | + { label: "Beta", description: "Use the Beta label" }, |
| 105 | + { label: "Other", description: "Use the Other label" }, |
| 106 | + ], |
| 107 | + }, |
| 108 | + ]); |
| 109 | + }); |
| 110 | + |
| 111 | + it("maps UI question ids back to xAI question text in accepted responses", () => { |
| 112 | + const response = makeXAiAskUserQuestionResponse( |
| 113 | + { |
| 114 | + sessionId: "session-1", |
| 115 | + toolCallId: "tool-call-1", |
| 116 | + mode: "default", |
| 117 | + questions: [ |
| 118 | + { |
| 119 | + id: "scope", |
| 120 | + question: "Which scope should Grok use?", |
| 121 | + options: [ |
| 122 | + { label: "workspace", description: "Use the current workspace" }, |
| 123 | + { label: "session", description: "Only use this session" }, |
| 124 | + ], |
| 125 | + }, |
| 126 | + ], |
| 127 | + }, |
| 128 | + { scope: "workspace" }, |
| 129 | + ); |
| 130 | + |
| 131 | + expect(response).toEqual({ |
| 132 | + outcome: "accepted", |
| 133 | + answers: { |
| 134 | + "Which scope should Grok use?": ["workspace"], |
| 135 | + }, |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + it("orders accepted answers by the original xAI question order", () => { |
| 140 | + const response = makeXAiAskUserQuestionResponse( |
| 141 | + { |
| 142 | + sessionId: "session-1", |
| 143 | + toolCallId: "tool-call-1", |
| 144 | + mode: "default", |
| 145 | + questions: [ |
| 146 | + { |
| 147 | + id: "first", |
| 148 | + question: "First question?", |
| 149 | + options: [{ label: "A", description: "A" }], |
| 150 | + }, |
| 151 | + { |
| 152 | + id: "second", |
| 153 | + question: "Second question?", |
| 154 | + options: [{ label: "B", description: "B" }], |
| 155 | + }, |
| 156 | + ], |
| 157 | + }, |
| 158 | + { |
| 159 | + second: "B", |
| 160 | + first: "A", |
| 161 | + }, |
| 162 | + ); |
| 163 | + |
| 164 | + expect(Object.keys(response.answers)).toEqual(["First question?", "Second question?"]); |
| 165 | + expect(response).toMatchObject({ |
| 166 | + outcome: "accepted", |
| 167 | + answers: { |
| 168 | + "First question?": ["A"], |
| 169 | + "Second question?": ["B"], |
| 170 | + }, |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + it("encodes typed custom answers as xAI Other annotations", () => { |
| 175 | + const response = makeXAiAskUserQuestionResponse( |
| 176 | + { |
| 177 | + method: "x.ai/ask_user_question", |
| 178 | + params: { |
| 179 | + sessionId: "session-1", |
| 180 | + toolCallId: "tool-call-1", |
| 181 | + mode: "default", |
| 182 | + questions: [ |
| 183 | + { |
| 184 | + question: "Which ice cream flavor?", |
| 185 | + options: [ |
| 186 | + { label: "vanilla", description: "Vanilla flavor" }, |
| 187 | + { label: "chocolate", description: "Chocolate flavor" }, |
| 188 | + ], |
| 189 | + }, |
| 190 | + ], |
| 191 | + }, |
| 192 | + }, |
| 193 | + { "Which ice cream flavor?": "pistachio" }, |
| 194 | + ); |
| 195 | + |
| 196 | + expect(response).toEqual({ |
| 197 | + outcome: "accepted", |
| 198 | + answers: { |
| 199 | + "Which ice cream flavor?": ["Other"], |
| 200 | + }, |
| 201 | + annotations: { |
| 202 | + "Which ice cream flavor?": { |
| 203 | + notes: "pistachio", |
| 204 | + }, |
| 205 | + }, |
| 206 | + }); |
| 207 | + }); |
| 208 | + |
| 209 | + it("encodes interrupted dialogs as xAI cancelled responses", () => { |
| 210 | + expect(makeXAiAskUserQuestionCancelledResponse()).toEqual({ |
| 211 | + outcome: "cancelled", |
| 212 | + }); |
| 213 | + }); |
| 214 | + |
| 215 | + it("does not echo preview annotations for multi-select answers", () => { |
| 216 | + const response = makeXAiAskUserQuestionResponse( |
| 217 | + { |
| 218 | + sessionId: "session-1", |
| 219 | + toolCallId: "tool-call-1", |
| 220 | + mode: "default", |
| 221 | + questions: [ |
| 222 | + { |
| 223 | + question: "Which files should Grok touch?", |
| 224 | + multiSelect: true, |
| 225 | + options: [ |
| 226 | + { |
| 227 | + label: "Tests", |
| 228 | + description: "Update tests", |
| 229 | + preview: "test preview", |
| 230 | + }, |
| 231 | + { |
| 232 | + label: "Docs", |
| 233 | + description: "Update docs", |
| 234 | + preview: "docs preview", |
| 235 | + }, |
| 236 | + ], |
| 237 | + }, |
| 238 | + ], |
| 239 | + }, |
| 240 | + { "Which files should Grok touch?": ["Tests", "Docs"] }, |
| 241 | + ); |
| 242 | + |
| 243 | + expect(response).toEqual({ |
| 244 | + outcome: "accepted", |
| 245 | + answers: { |
| 246 | + "Which files should Grok touch?": ["Tests", "Docs"], |
| 247 | + }, |
| 248 | + }); |
| 249 | + }); |
72 | 250 | }); |
0 commit comments