-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathextension.test.ts
More file actions
110 lines (91 loc) · 4.29 KB
/
Copy pathextension.test.ts
File metadata and controls
110 lines (91 loc) · 4.29 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
import { afterEach, describe, expect, it, vi } from "vitest";
import { CopilotClient } from "../src/client.js";
import { approveAll } from "../src/index.js";
import { createCanvas, defineWorkflow, joinSession } from "../src/extension.js";
import { defaultJoinSessionPermissionHandler } from "../src/types.js";
describe("joinSession", () => {
const originalSessionId = process.env.SESSION_ID;
afterEach(() => {
if (originalSessionId === undefined) {
delete process.env.SESSION_ID;
} else {
process.env.SESSION_ID = originalSessionId;
}
vi.restoreAllMocks();
});
it("defaults onPermissionRequest to no-result", async () => {
process.env.SESSION_ID = "session-123";
const resumeForExtension = vi
.spyOn(CopilotClient.prototype, "resumeSessionForExtension")
.mockResolvedValue({} as any);
await joinSession({ tools: [] });
const [, config] = resumeForExtension.mock.calls[0]!;
expect(config.onPermissionRequest).toBeDefined();
expect(config.onPermissionRequest).toBe(defaultJoinSessionPermissionHandler);
const result = await Promise.resolve(
config.onPermissionRequest!({ kind: "write" }, { sessionId: "session-123" })
);
expect(result).toEqual({ kind: "no-result" });
expect(config.suppressResumeEvent).toBe(true);
});
it("preserves an explicit onPermissionRequest handler", async () => {
process.env.SESSION_ID = "session-123";
const resumeForExtension = vi
.spyOn(CopilotClient.prototype, "resumeSessionForExtension")
.mockResolvedValue({} as any);
await joinSession({ onPermissionRequest: approveAll, suppressResumeEvent: false });
const [, config] = resumeForExtension.mock.calls[0]!;
expect(config.onPermissionRequest).toBe(approveAll);
expect(config.suppressResumeEvent).toBe(false);
});
it("forwards the requested environment variables and keeps them off the resume config", async () => {
process.env.SESSION_ID = "session-123";
const resumeForExtension = vi
.spyOn(CopilotClient.prototype, "resumeSessionForExtension")
.mockResolvedValue({} as any);
await joinSession({
requestedEnvironmentVariables: ["GITHUB_TOKEN", "MY_SECRET"],
tools: [],
});
const [, config, , extensionOptions] = resumeForExtension.mock.calls[0]!;
expect(extensionOptions).toEqual({
requestedEnvironmentVariables: ["GITHUB_TOKEN", "MY_SECRET"],
});
expect(config).not.toHaveProperty("requestedEnvironmentVariables");
});
it("requests no environment variables when the option is omitted or empty", async () => {
process.env.SESSION_ID = "session-123";
const resumeForExtension = vi
.spyOn(CopilotClient.prototype, "resumeSessionForExtension")
.mockResolvedValue({} as any);
await joinSession({ tools: [] });
await joinSession({ requestedEnvironmentVariables: [], tools: [] });
expect(resumeForExtension.mock.calls[0]![3]).toBeUndefined();
// An empty list means the same as omitting the option, so it must not put
// an environment request on the wire either.
expect(resumeForExtension.mock.calls[1]![3]).toBeUndefined();
});
it("forwards workflow contributions independently", async () => {
process.env.SESSION_ID = "session-123";
const resumeForExtension = vi
.spyOn(CopilotClient.prototype, "resumeSessionForExtension")
.mockResolvedValue({} as any);
const workflow = defineWorkflow({
meta: { name: "review", description: "Review", phases: [] },
run: async () => null,
});
await joinSession({ workflows: [workflow] });
expect(resumeForExtension.mock.calls[0]![2]).toEqual({
workflows: [workflow],
});
});
it("exports the canvas helper from the extension surface", () => {
const canvas = createCanvas({
id: "counter",
displayName: "Counter",
description: "A counter canvas",
open: () => ({ url: "https://example.test/counter" }),
});
expect(canvas.declaration.id).toBe("counter");
});
});