-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask-question.test.ts
More file actions
43 lines (39 loc) · 1.37 KB
/
Copy pathask-question.test.ts
File metadata and controls
43 lines (39 loc) · 1.37 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
import assert from "node:assert/strict";
import test from "node:test";
import type { AgentToolResult, ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import askQuestionExtension from "../extensions/ask-question.ts";
type Details = { answer: string | null; selectedIndex?: number };
type RegisteredTool = {
execute(
toolCallId: string,
params: { question: string; options: Array<{ label: string; description?: string }> },
signal: AbortSignal | undefined,
onUpdate: undefined,
ctx: ExtensionContext,
): Promise<AgentToolResult<Details>>;
};
function loadTool(): RegisteredTool {
let tool: RegisteredTool | undefined;
askQuestionExtension({
registerTool(definition) {
tool = definition as unknown as RegisteredTool;
},
} as ExtensionAPI);
assert.ok(tool);
return tool;
}
test("returns the selected source option when display labels would otherwise collide", async () => {
const ctx = {
mode: "tui",
ui: {
select: async (_title: string, choices: string[]) => choices[1],
input: async () => undefined,
},
} as unknown as ExtensionContext;
const result = await loadTool().execute("call-1", {
question: "Choose one",
options: [{ label: "A" }, { label: "A (Recommended)" }],
}, new AbortController().signal, undefined, ctx);
assert.equal(result.details?.answer, "A (Recommended)");
assert.equal(result.details?.selectedIndex, 2);
});