Elffuss BraidHub

kikocis/continue public

3ff29c567dd0 · 3.7 KiBRawPermalink
1import type { ChatHistoryItem } from "core/index.js";
2import { convertFromUnifiedHistory } from "core/util/messageConversion.js";
3
4describe("convertFromUnifiedHistory", () => {
5 it("should expand contextItems into user message content", () => {
6 const historyItems: ChatHistoryItem[] = [
7 {
8 message: {
9 role: "user",
10 content: "Please review @test-file.txt",
11 },
12 contextItems: [
13 {
14 id: {
15 providerTitle: "file",
16 itemId: "550e8400-e29b-41d4-a716-446655440000",
17 },
18 content: "console.log('Hello, world!');",
19 name: "test-file.txt",
20 description: "File: test-file.txt",
21 uri: {
22 type: "file",
23 value: "file:///Users/user/test-file.txt",
24 },
25 },
26 ],
27 },
28 ];
29
30 const result = convertFromUnifiedHistory(historyItems);
31
32 expect(result).toHaveLength(1);
33 expect(result[0]).toEqual({
34 role: "user",
35 content:
36 "<context name=\"test-file.txt\">\nconsole.log('Hello, world!');\n</context>\n\nPlease review @test-file.txt",
37 });
38 });
39
40 it("should handle user messages without contextItems", () => {
41 const historyItems: ChatHistoryItem[] = [
42 {
43 message: {
44 role: "user",
45 content: "Hello",
46 },
47 contextItems: [],
48 },
49 ];
50
51 const result = convertFromUnifiedHistory(historyItems);
52
53 expect(result).toHaveLength(1);
54 expect(result[0]).toEqual({
55 role: "user",
56 content: "Hello",
57 });
58 });
59
60 it("should handle multiple contextItems", () => {
61 const historyItems: ChatHistoryItem[] = [
62 {
63 message: {
64 role: "user",
65 content: "Compare @file1.js and @file2.js",
66 },
67 contextItems: [
68 {
69 id: {
70 providerTitle: "file",
71 itemId: "550e8400-e29b-41d4-a716-446655440000",
72 },
73 content: "const a = 1;",
74 name: "file1.js",
75 description: "File: file1.js",
76 uri: {
77 type: "file",
78 value: "file:///Users/user/file1.js",
79 },
80 },
81 {
82 id: {
83 providerTitle: "file",
84 itemId: "550e8400-e29b-41d4-a716-446655440001",
85 },
86 content: "const b = 2;",
87 name: "file2.js",
88 description: "File: file2.js",
89 uri: {
90 type: "file",
91 value: "file:///Users/user/file2.js",
92 },
93 },
94 ],
95 },
96 ];
97
98 const result = convertFromUnifiedHistory(historyItems);
99
100 expect(result).toHaveLength(1);
101 expect(result[0]).toEqual({
102 role: "user",
103 content:
104 '<context name="file1.js">\nconst a = 1;\n</context>\n\n<context name="file2.js">\nconst b = 2;\n</context>\n\nCompare @file1.js and @file2.js',
105 });
106 });
107
108 it("should not expand contextItems for non-user messages", () => {
109 const historyItems: ChatHistoryItem[] = [
110 {
111 message: {
112 role: "assistant",
113 content: "Here's the analysis",
114 },
115 contextItems: [
116 {
117 id: {
118 providerTitle: "file",
119 itemId: "550e8400-e29b-41d4-a716-446655440000",
120 },
121 content: "some content",
122 name: "file.txt",
123 description: "File: file.txt",
124 uri: {
125 type: "file",
126 value: "file:///Users/user/file.txt",
127 },
128 },
129 ],
130 },
131 ];
132
133 const result = convertFromUnifiedHistory(historyItems);
134
135 expect(result).toHaveLength(1);
136 expect(result[0]).toEqual({
137 role: "assistant",
138 content: "Here's the analysis",
139 });
140 });
141});