-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathaskUserQuestion.test.ts
More file actions
111 lines (102 loc) · 3.3 KB
/
askUserQuestion.test.ts
File metadata and controls
111 lines (102 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { test } from "node:test";
import assert from "node:assert/strict";
import { findPendingAskUserQuestion, formatAskUserQuestionAnswers, formatAskUserQuestionDecline } from "../ui";
import type { SessionMessage } from "../session";
function message(content: unknown): SessionMessage {
const now = "2026-04-29T00:00:00.000Z";
return {
id: "tool-message",
sessionId: "session-id",
role: "tool",
content: JSON.stringify(content),
contentParams: null,
messageParams: { tool_call_id: "call-id" },
compacted: false,
visible: true,
createTime: now,
updateTime: now,
};
}
test("findPendingAskUserQuestion returns latest pending AskUserQuestion tool message", () => {
const pending = findPendingAskUserQuestion(
[
message({ ok: true, name: "read" }),
message({
ok: true,
name: "AskUserQuestion",
awaitUserResponse: true,
metadata: {
kind: "ask_user_question",
questions: [
{
question: "Which package manager should we use?",
options: [{ label: "npm", description: "Use package-lock.json." }, { label: "yarn" }],
},
],
},
}),
],
"waiting_for_user"
);
assert.equal(pending?.messageId, "tool-message");
assert.equal(pending?.questions[0]?.question, "Which package manager should we use?");
assert.equal(pending?.questions[0]?.options[0]?.description, "Use package-lock.json.");
});
test("findPendingAskUserQuestion preserves multiple pending questions in order", () => {
const pending = findPendingAskUserQuestion(
[
message({
ok: true,
name: "AskUserQuestion",
awaitUserResponse: true,
metadata: {
kind: "ask_user_question",
questions: [
{
question: "Use default description?",
options: [{ label: "Yes" }, { label: "Custom" }],
},
{
question: "Where should the project be created?",
options: [{ label: "Current directory" }, { label: "Custom path" }],
},
],
},
}),
],
"waiting_for_user"
);
assert.deepEqual(
pending?.questions.map((question) => question.question),
["Use default description?", "Where should the project be created?"]
);
});
test("findPendingAskUserQuestion ignores questions unless session waits for user", () => {
const pending = findPendingAskUserQuestion(
[
message({
ok: true,
name: "AskUserQuestion",
awaitUserResponse: true,
metadata: {
kind: "ask_user_question",
questions: [{ question: "Continue?", options: [{ label: "Yes" }] }],
},
}),
],
"processing"
);
assert.equal(pending, null);
});
test("formatAskUserQuestionAnswers creates model-readable answer text", () => {
assert.equal(
formatAskUserQuestionAnswers({
"Which package manager?": "yarn",
"Any notes?": "Use the existing lockfile",
}),
'User has answered your questions: "Which package manager?"="yarn", "Any notes?"="Use the existing lockfile". You can now continue with the user\'s answers in mind.'
);
});
test("formatAskUserQuestionDecline creates decline text", () => {
assert.match(formatAskUserQuestionDecline(), /declined to answer/);
});