|
|
@@ -8,6 +8,7 @@ import { ExtensionMessage, ExtensionState } from "../../../shared/ExtensionMessa
|
|
|
import { setSoundEnabled } from "../../../utils/sound"
|
|
|
import { defaultModeSlug } from "../../../shared/modes"
|
|
|
import { experimentDefault } from "../../../shared/experiments"
|
|
|
+import { Cline } from "../../Cline"
|
|
|
|
|
|
// Mock custom-instructions module
|
|
|
const mockAddCustomInstructions = jest.fn()
|
|
|
@@ -377,15 +378,43 @@ describe("ClineProvider", () => {
|
|
|
})
|
|
|
|
|
|
test("clearTask aborts current task", async () => {
|
|
|
+ // prepare the mock object
|
|
|
const mockAbortTask = jest.fn()
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- provider.cline = { abortTask: mockAbortTask }
|
|
|
+ const clineMock = { abortTask: mockAbortTask } as unknown as Cline
|
|
|
+
|
|
|
+ // add the mock object to the stack
|
|
|
+ provider.addClineToStack(clineMock)
|
|
|
|
|
|
+ // get the stack size before the abort call
|
|
|
+ const stackSizeBeforeAbort = provider.getClineStackSize()
|
|
|
+
|
|
|
+ // call the removeClineFromStack method so it will call the current cline abort and remove it from the stack
|
|
|
await provider.removeClineFromStack()
|
|
|
|
|
|
+ // get the stack size after the abort call
|
|
|
+ const stackSizeAfterAbort = provider.getClineStackSize()
|
|
|
+
|
|
|
+ // check if the abort method was called
|
|
|
expect(mockAbortTask).toHaveBeenCalled()
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- expect(provider.cline).toBeUndefined()
|
|
|
+
|
|
|
+ // check if the stack size was decreased
|
|
|
+ expect(stackSizeBeforeAbort - stackSizeAfterAbort).toBe(1)
|
|
|
+ })
|
|
|
+
|
|
|
+ test("addClineToStack adds multiple Cline instances to the stack", () => {
|
|
|
+ // prepare test data
|
|
|
+ const mockCline1 = { taskId: "test-task-id-1" } as unknown as Cline
|
|
|
+ const mockCline2 = { taskId: "test-task-id-2" } as unknown as Cline
|
|
|
+
|
|
|
+ // add Cline instances to the stack
|
|
|
+ provider.addClineToStack(mockCline1)
|
|
|
+ provider.addClineToStack(mockCline2)
|
|
|
+
|
|
|
+ // verify cline instances were added to the stack
|
|
|
+ expect(provider.getClineStackSize()).toBe(2)
|
|
|
+
|
|
|
+ // verify current cline instance is the last one added
|
|
|
+ expect(provider.getCurrentCline()).toBe(mockCline2)
|
|
|
})
|
|
|
|
|
|
test("getState returns correct initial state", async () => {
|
|
|
@@ -788,9 +817,8 @@ describe("ClineProvider", () => {
|
|
|
taskId: "test-task-id",
|
|
|
abortTask: jest.fn(),
|
|
|
handleWebviewAskResponse: jest.fn(),
|
|
|
- }
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- provider.cline = mockCline
|
|
|
+ } as unknown as Cline
|
|
|
+ provider.addClineToStack(mockCline)
|
|
|
|
|
|
// Mock getTaskWithId
|
|
|
;(provider as any).getTaskWithId = jest.fn().mockResolvedValue({
|
|
|
@@ -841,9 +869,8 @@ describe("ClineProvider", () => {
|
|
|
taskId: "test-task-id",
|
|
|
abortTask: jest.fn(),
|
|
|
handleWebviewAskResponse: jest.fn(),
|
|
|
- }
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- provider.cline = mockCline
|
|
|
+ } as unknown as Cline
|
|
|
+ provider.addClineToStack(mockCline)
|
|
|
|
|
|
// Mock getTaskWithId
|
|
|
;(provider as any).getTaskWithId = jest.fn().mockResolvedValue({
|
|
|
@@ -871,9 +898,8 @@ describe("ClineProvider", () => {
|
|
|
overwriteClineMessages: jest.fn(),
|
|
|
overwriteApiConversationHistory: jest.fn(),
|
|
|
taskId: "test-task-id",
|
|
|
- }
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- provider.cline = mockCline
|
|
|
+ } as unknown as Cline
|
|
|
+ provider.addClineToStack(mockCline)
|
|
|
|
|
|
// Trigger message deletion
|
|
|
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
|
|
|
@@ -1377,9 +1403,8 @@ describe("ClineProvider", () => {
|
|
|
const mockCline = {
|
|
|
api: undefined,
|
|
|
abortTask: jest.fn(),
|
|
|
- }
|
|
|
- // @ts-ignore - accessing private property for testing
|
|
|
- provider.cline = mockCline
|
|
|
+ } as unknown as Cline
|
|
|
+ provider.addClineToStack(mockCline)
|
|
|
|
|
|
const testApiConfig = {
|
|
|
apiProvider: "anthropic" as const,
|