-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsession_config.test.ts
More file actions
78 lines (63 loc) · 2.73 KB
/
session_config.test.ts
File metadata and controls
78 lines (63 loc) · 2.73 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
import { describe, expect, it } from "vitest";
import { writeFile, mkdir } from "fs/promises";
import { join } from "path";
import { approveAll } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
describe("Session Configuration", async () => {
const { copilotClient: client, workDir } = await createSdkTestContext();
it("should use workingDirectory for tool execution", async () => {
const subDir = join(workDir, "subproject");
await mkdir(subDir, { recursive: true });
await writeFile(join(subDir, "marker.txt"), "I am in the subdirectory");
const session = await client.createSession({
onPermissionRequest: approveAll,
workingDirectory: subDir,
});
const assistantMessage = await session.sendAndWait({
prompt: "Read the file marker.txt and tell me what it says",
});
expect(assistantMessage?.data.content).toContain("subdirectory");
await session.disconnect();
});
it("should create session with custom provider config", async () => {
const session = await client.createSession({
onPermissionRequest: approveAll,
provider: {
baseUrl: "https://api.example.com/v1",
apiKey: "test-key",
},
});
expect(session.sessionId).toMatch(/^[a-f0-9-]+$/);
try {
await session.disconnect();
} catch {
// disconnect may fail since the provider is fake
}
});
it("should accept blob attachments", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
await session.send({
prompt: "Describe this image",
attachments: [
{
type: "blob",
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
mimeType: "image/png",
displayName: "test-pixel.png",
},
],
});
// Just verify send doesn't throw — blob attachment support varies by runtime
await session.disconnect();
});
it("should accept message attachments", async () => {
await writeFile(join(workDir, "attached.txt"), "This file is attached");
const session = await client.createSession({ onPermissionRequest: approveAll });
await session.send({
prompt: "Summarize the attached file",
attachments: [{ type: "file", path: join(workDir, "attached.txt") }],
});
// Just verify send doesn't throw — attachment support varies by runtime
await session.disconnect();
});
});