-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrpc_workspace_checkpoints.e2e.test.ts
More file actions
76 lines (68 loc) · 3.25 KB
/
rpc_workspace_checkpoints.e2e.test.ts
File metadata and controls
76 lines (68 loc) · 3.25 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { existsSync, readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { approveAll } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
describe("Session workspace checkpoint RPC", async () => {
const { copilotClient: client } = await createSdkTestContext();
it("should list no checkpoints for fresh session", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
const result = await session.rpc.workspaces.listCheckpoints();
expect(result.checkpoints).toEqual([]);
} finally {
await session.disconnect();
}
});
it("should return null or empty content for unknown checkpoint", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
const result = await session.rpc.workspaces.readCheckpoint({
number: Number.MAX_SAFE_INTEGER,
});
expect(result.content ?? "").toBe("");
} finally {
await session.disconnect();
}
});
it("should return typed workspace diff result", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
const result = await session.rpc.workspaces.diff({ mode: "unstaged" });
expect(result.requestedMode).toBe("unstaged");
expect(["unstaged", "branch"]).toContain(result.mode);
expect(Array.isArray(result.changes)).toBe(true);
for (const change of result.changes) {
expect(change.path.trim()).toBeTruthy();
expect(["added", "modified", "deleted", "renamed"]).toContain(change.changeType);
expect(typeof change.diff).toBe("string");
}
} finally {
await session.disconnect();
}
});
it("should save large paste and expose readable content", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
try {
const content = "Large paste payload 🚀\n".repeat(512);
const result = await session.rpc.workspaces.saveLargePaste({ content });
const saved = result.saved;
expect(saved).not.toBeNull();
expect(saved!.filename.trim()).toBeTruthy();
expect(saved!.filePath.trim()).toBeTruthy();
expect(saved!.sizeBytes).toBe(Buffer.byteLength(content, "utf8"));
try {
const read = await session.rpc.workspaces.readFile({ path: saved!.filename });
expect(read.content).toBe(content);
} catch (err: unknown) {
expect(existsSync(saved!.filePath)).toBe(true);
expect(readFileSync(saved!.filePath, "utf8")).toBe(content);
expect(err).toBeDefined();
}
} finally {
await session.disconnect();
}
});
});