Elffuss BraidHub

kikocis/continue public

fix: tests
Changeset1c83b0b1adf27e2a947795f59bd1e032ee06aea73a39126e0eba9059d89053ca
AuthorNate <sestinj@gmail.com> · 2025-08-23 10:50 -07:00
CommitterNate <sestinj@gmail.com> · 2025-08-23 10:50 -07:00
Parents15bc6182e084

Browse the files at this changeset

3 files changed

modified extensions/cli/src/compaction.pruneLastMessage.test.ts +45 −45
@@ -9,123 +9,123 @@
99 expect(result).toEqual([]);
1010 });
1111
12- it("should preserve history ending with assistant message", () => {
12+ it("should remove single user message", () => {
1313 const history: ChatCompletionMessageParam[] = [
14- { role: "system", content: "System" },
1514 { role: "user", content: "Hello" },
16- { role: "assistant", content: "Hi there" },
1715 ];
1816
1917 const result = pruneLastMessage(history);
20- expect(result).toEqual(history);
18+ expect(result).toEqual([]);
2119 });
2220
23- it("should preserve history ending with tool message", () => {
21+ it("should return empty array for single system message", () => {
2422 const history: ChatCompletionMessageParam[] = [
2523 { role: "system", content: "System" },
26- { role: "user", content: "Run command" },
27- { role: "assistant", content: "Running...", tool_calls: [{ id: "1" } as any] },
28- { role: "tool", content: "Command output", tool_call_id: "1" },
2924 ];
3025
3126 const result = pruneLastMessage(history);
32- expect(result).toEqual(history);
27+ expect(result).toEqual([]);
3328 });
3429
35- it("should prune user messages at the end", () => {
30+ it("should return empty array for single assistant message", () => {
3631 const history: ChatCompletionMessageParam[] = [
37- { role: "system", content: "System" },
38- { role: "user", content: "Hello" },
39- { role: "assistant", content: "Hi there" },
40- { role: "user", content: "Another question" },
32+ { role: "assistant", content: "Hello" },
4133 ];
4234
4335 const result = pruneLastMessage(history);
44- expect(result).toEqual([
45- { role: "system", content: "System" },
46- { role: "user", content: "Hello" },
47- { role: "assistant", content: "Hi there" },
48- ]);
36+ expect(result).toEqual([]);
37+ });
38+
39+ it("should return empty array for single tool message", () => {
40+ const history: ChatCompletionMessageParam[] = [
41+ { role: "tool", content: "Tool output", tool_call_id: "1" },
42+ ];
43+
44+ const result = pruneLastMessage(history);
45+ expect(result).toEqual([]);
4946 });
5047
51- it("should prune multiple user messages at the end", () => {
48+ it("should remove last message when second-to-last is user", () => {
5249 const history: ChatCompletionMessageParam[] = [
5350 { role: "system", content: "System" },
5451 { role: "user", content: "Hello" },
5552 { role: "assistant", content: "Hi there" },
56- { role: "user", content: "Question 1" },
57- { role: "user", content: "Question 2" },
5853 ];
5954
6055 const result = pruneLastMessage(history);
6156 expect(result).toEqual([
6257 { role: "system", content: "System" },
63- { role: "user", content: "Hello" },
64- { role: "assistant", content: "Hi there" },
6558 ]);
6659 });
6760
68- it("should handle tool call sequences correctly", () => {
61+ it("should remove assistant+tool sequence when second-to-last is assistant with tool calls", () => {
6962 const history: ChatCompletionMessageParam[] = [
7063 { role: "system", content: "System" },
71- { role: "user", content: "Do something" },
72- { role: "assistant", content: "I'll help", tool_calls: [{ id: "1" } as any] },
73- { role: "tool", content: "Tool result", tool_call_id: "1" },
74- { role: "user", content: "Follow up question" },
64+ { role: "user", content: "Run command" },
65+ { role: "assistant", content: "Running...", tool_calls: [{ id: "1" } as any] },
66+ { role: "tool", content: "Command output", tool_call_id: "1" },
7567 ];
7668
7769 const result = pruneLastMessage(history);
7870 expect(result).toEqual([
7971 { role: "system", content: "System" },
80- { role: "user", content: "Do something" },
81- { role: "assistant", content: "I'll help", tool_calls: [{ id: "1" } as any] },
82- { role: "tool", content: "Tool result", tool_call_id: "1" },
72+ { role: "user", content: "Run command" },
8373 ]);
8474 });
8575
86- it("should return only system message when no assistant/tool messages exist", () => {
76+ it("should prune last message when second-to-last is not user or assistant with tool calls", () => {
8777 const history: ChatCompletionMessageParam[] = [
8878 { role: "system", content: "System" },
89- { role: "user", content: "Hello" },
90- { role: "user", content: "Another message" },
79+ { role: "assistant", content: "Hi there" },
80+ { role: "user", content: "Another question" },
9181 ];
9282
9383 const result = pruneLastMessage(history);
9484 expect(result).toEqual([
9585 { role: "system", content: "System" },
86+ { role: "assistant", content: "Hi there" },
9687 ]);
9788 });
9889
99- it("should return empty array when no system message and no assistant/tool messages", () => {
90+ it("should handle multiple user messages by removing two at a time", () => {
10091 const history: ChatCompletionMessageParam[] = [
101- { role: "user", content: "Hello" },
102- { role: "user", content: "Another message" },
92+ { role: "system", content: "System" },
93+ { role: "user", content: "Question 1" },
94+ { role: "user", content: "Question 2" },
10395 ];
10496
10597 const result = pruneLastMessage(history);
106- expect(result).toEqual([]);
98+ expect(result).toEqual([
99+ { role: "system", content: "System" },
100+ ]);
107101 });
108102
109- it("should handle history with only system message", () => {
103+ it("should handle tool call sequences by removing user after tool", () => {
110104 const history: ChatCompletionMessageParam[] = [
111105 { role: "system", content: "System" },
106+ { role: "user", content: "Do something" },
107+ { role: "assistant", content: "I'll help", tool_calls: [{ id: "1" } as any] },
108+ { role: "tool", content: "Tool result", tool_call_id: "1" },
109+ { role: "user", content: "Follow up question" },
112110 ];
113111
114112 const result = pruneLastMessage(history);
115113 expect(result).toEqual([
116114 { role: "system", content: "System" },
115+ { role: "user", content: "Do something" },
116+ { role: "assistant", content: "I'll help", tool_calls: [{ id: "1" } as any] },
117+ { role: "tool", content: "Tool result", tool_call_id: "1" },
117118 ]);
118119 });
119120
120- it("should handle history with only assistant message", () => {
121+ it("should remove both user messages when consecutive", () => {
121122 const history: ChatCompletionMessageParam[] = [
122- { role: "assistant", content: "Hello" },
123+ { role: "user", content: "Hello" },
124+ { role: "user", content: "Another message" },
123125 ];
124126
125127 const result = pruneLastMessage(history);
126- expect(result).toEqual([
127- { role: "assistant", content: "Hello" },
128- ]);
128+ expect(result).toEqual([]);
129129 });
130130
131131 it("should handle complex conversation flow", () => {
modified extensions/cli/src/compaction.ts +5 −0
@@ -169,6 +169,11 @@
169169 return chatHistory;
170170 }
171171
172+ if (chatHistory.length === 1) {
173+ // Only one message - always return empty array
174+ return [];
175+ }
176+
172177 const secondToLastIndex = chatHistory.length - 2;
173178 const secondToLastMessage = chatHistory[secondToLastIndex];
174179
modified extensions/cli/src/slashCommands.test.ts +1 −1
@@ -108,7 +108,7 @@
108108 expect(result?.output).toContain("Authentication:");
109109 expect(result?.output).toContain("Authenticated via environment variable");
110110 expect(result?.output).toContain("Configuration:");
111- expect(result?.output).toContain("Using default configuration");
111+ expect(result?.output).toContain("Config not found");
112112 expect(result?.exit).toBe(false);
113113 });
114114