forked from yusuf8834/bb-git-history
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.ts
More file actions
116 lines (109 loc) · 3.24 KB
/
Copy pathserver.test.ts
File metadata and controls
116 lines (109 loc) · 3.24 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
111
112
113
114
115
116
import {
createFakePluginHost,
makeThreadResponse,
} from "@get-bb/plugin-sdk/testing";
import { describe, expect, it } from "vitest";
import type { HistoryPage } from "./contracts";
import plugin from "./server";
describe("Git history server", () => {
it("checks the host when cached environment metadata says non-Git", async () => {
const thread = {
...makeThreadResponse({
id: "thread-1",
projectId: "project-1",
environmentId: "environment-1",
}),
environment: {
id: "environment-1",
projectId: "project-1",
hostId: "host-1",
name: null,
path: "/workspace/plain-folder",
branchName: null,
baseBranch: null,
defaultBranch: null,
mergeBaseBranch: null,
isGitRepo: false,
isWorktree: false,
managed: false,
status: "ready" as const,
workspaceProvisionType: "unmanaged" as const,
createdAt: 1,
updatedAt: 1,
},
};
const historyPage: HistoryPage = {
repoName: "late-init-repo",
currentBranch: "main",
uncommittedFiles: [],
commits: [],
offset: 0,
total: 0,
hasMore: false,
revision: "abc123\0main\0",
unavailableReason: null,
};
const { bb, harness } = createFakePluginHost({
pluginId: "git-history",
sdk: {
threads: {
get: async () => thread,
},
},
experimental_callHostRpc: async ({ method }) => method === "workingPatch"
? { path: "README.md", patch: "@@ -1 +1,2 @@", truncated: false }
: historyPage,
});
plugin(bb);
expect(harness.registrations.settingsDescriptors.showHeaderShortcut).toEqual({
type: "boolean",
label: "Show thread header shortcut",
description: "Show Git History beside the editor controls. Git History remains available from New tab.",
default: false,
});
expect(harness.registrations.settingsDescriptors.experimentalCommitGraph).toEqual({
type: "boolean",
label: "Experimental commit graph",
description: "Show branch and merge lanes in Git History.",
default: true,
});
const result = (await harness.behavior.callRpc("history", {
threadId: "thread-1",
offset: 0,
limit: 200,
})) as HistoryPage;
expect(result.repoName).toBe("late-init-repo");
expect(result.currentBranch).toBe("main");
expect(result.unavailableReason).toBeNull();
expect(result.commits).toEqual([]);
expect(harness.inspection.experimental_hostRpcCalls).toEqual([
{
method: "history",
hostId: "host-1",
input: {
repoPath: "/workspace/plain-folder",
offset: 0,
limit: 200,
},
},
]);
const patch = await harness.behavior.callRpc("workingPatch", {
threadId: "thread-1",
path: "README.md",
});
expect(patch).toEqual({
path: "README.md",
patch: "@@ -1 +1,2 @@",
truncated: false,
});
expect(harness.inspection.experimental_hostRpcCalls.at(-1)).toEqual({
method: "workingPatch",
hostId: "host-1",
input: {
repoPath: "/workspace/plain-folder",
path: "README.md",
},
});
await harness.lifecycle.dispose();
});
});