-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrpc_remote.e2e.test.ts
More file actions
94 lines (86 loc) · 3.78 KB
/
rpc_remote.e2e.test.ts
File metadata and controls
94 lines (86 loc) · 3.78 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { describe, expect, it } from "vitest";
import { approveAll } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
import { waitForCondition } from "./harness/sdkTestHelper.js";
describe("Session remote RPC", async () => {
const { copilotClient: client } = await createSdkTestContext();
async function expectImplemented(
action: () => Promise<unknown>,
method: string
): Promise<unknown> {
try {
return await action();
} catch (err: unknown) {
const text = err instanceof Error ? `${err.message}\n${err.stack ?? ""}` : String(err);
expect(text.toLowerCase()).not.toContain(`unhandled method ${method.toLowerCase()}`);
return undefined;
}
}
it("should treat remote off as no-op or implemented error", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
const result = (await expectImplemented(
() => session.rpc.remote.enable({ mode: "off" }),
"session.remote.enable"
)) as Awaited<ReturnType<typeof session.rpc.remote.enable>> | undefined;
if (result) {
expect(result.remoteSteerable).toBe(false);
expect(result.url ?? "").toBe("");
}
} finally {
await session.disconnect();
}
});
it("should treat remote disable as no-op or implemented error", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
await expectImplemented(() => session.rpc.remote.disable(), "session.remote.disable");
} finally {
await session.disconnect();
}
});
it("should notify steerable changed event and persist flag", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
await session.rpc.remote.notifySteerableChanged({ remoteSteerable: true });
await waitForCondition(
async () =>
(await session.getEvents()).some(
(event) =>
event.type === "session.remote_steerable_changed" &&
event.data.remoteSteerable === true
),
{ timeoutMessage: "Timed out waiting for remote steerable=true event." }
);
expect(
(
await client.rpc.sessions.getPersistedRemoteSteerable({
sessionId: session.sessionId,
})
).remoteSteerable
).toBe(true);
await session.rpc.remote.notifySteerableChanged({ remoteSteerable: false });
await waitForCondition(
async () =>
(await session.getEvents()).some(
(event) =>
event.type === "session.remote_steerable_changed" &&
event.data.remoteSteerable === false
),
{ timeoutMessage: "Timed out waiting for remote steerable=false event." }
);
expect(
(
await client.rpc.sessions.getPersistedRemoteSteerable({
sessionId: session.sessionId,
})
).remoteSteerable
).toBe(false);
} finally {
await session.disconnect();
}
});
});