forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_turn.test.ts
More file actions
45 lines (37 loc) · 1.97 KB
/
Copy pathmulti_turn.test.ts
File metadata and controls
45 lines (37 loc) · 1.97 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { writeFile } from "fs/promises";
import { join } from "path";
import { describe, expect, it } from "vitest";
import { approveAll } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext";
describe("Multi-turn Tool Usage", async () => {
const { copilotClient: client, workDir } = await createSdkTestContext();
it("should use tool results from previous turns", async () => {
// Write a file, then ask the model to read it and reason about its content
await writeFile(join(workDir, "secret.txt"), "The magic number is 42.");
const session = await client.createSession({ onPermissionRequest: approveAll });
const msg1 = await session.sendAndWait({
prompt: "Read the file 'secret.txt' and tell me what the magic number is.",
});
expect(msg1?.data.content).toContain("42");
// Follow-up that requires context from the previous turn
const msg2 = await session.sendAndWait({
prompt: "What is that magic number multiplied by 2?",
});
expect(msg2?.data.content).toContain("84");
});
it("should handle file creation then reading across turns", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
// First turn: create a file
await session.sendAndWait({
prompt: "Create a file called 'greeting.txt' with the content 'Hello from multi-turn test'.",
});
// Second turn: read the file
const msg = await session.sendAndWait({
prompt: "Read the file 'greeting.txt' and tell me its exact contents.",
});
expect(msg?.data.content).toContain("Hello from multi-turn test");
});
});