Skip to content

Commit 233e398

Browse files
author
Eric Wheeler
committed
test: update UI tests after task history migration
- Removed pass-through state tests from ContextProxy that no longer apply - Updated ClineProvider tests to use file-based history instead of global state - Modified ChatTextArea tests to use useTaskSearch hook instead of taskHistory prop - Completely rewrote useTaskSearch tests to use message-based architecture - Updated other tests to remove taskHistory references from mock states Signed-off-by: Eric Wheeler <[email protected]> test: Fix ClineProvider test by mocking extension context and taskHistory This commit fixes the failing test 'correctly identifies subtask scenario for issue #4602' by: 1. Adding necessary Vitest imports 2. Mocking getExtensionContext to return a mock context with globalStorageUri 3. Mocking taskHistory module to prevent file system operations during tests Signed-off-by: Eric Wheeler <[email protected]>
1 parent 79d3096 commit 233e398

File tree

8 files changed

+427
-228
lines changed

8 files changed

+427
-228
lines changed

src/core/config/__tests__/ContextProxy.spec.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -102,41 +102,6 @@ describe("ContextProxy", () => {
102102
const result = proxy.getGlobalState("apiProvider", "deepseek")
103103
expect(result).toBe("deepseek")
104104
})
105-
106-
it("should bypass cache for pass-through state keys", async () => {
107-
// Setup mock return value
108-
mockGlobalState.get.mockReturnValue("pass-through-value")
109-
110-
// Use a pass-through key (taskHistory)
111-
const result = proxy.getGlobalState("taskHistory")
112-
113-
// Should get value directly from original context
114-
expect(result).toBe("pass-through-value")
115-
expect(mockGlobalState.get).toHaveBeenCalledWith("taskHistory")
116-
})
117-
118-
it("should respect default values for pass-through state keys", async () => {
119-
// Setup mock to return undefined
120-
mockGlobalState.get.mockReturnValue(undefined)
121-
122-
// Use a pass-through key with default value
123-
const historyItems = [
124-
{
125-
id: "1",
126-
number: 1,
127-
ts: 1,
128-
task: "test",
129-
tokensIn: 1,
130-
tokensOut: 1,
131-
totalCost: 1,
132-
},
133-
]
134-
135-
const result = proxy.getGlobalState("taskHistory", historyItems)
136-
137-
// Should return default value when original context returns undefined
138-
expect(result).toBe(historyItems)
139-
})
140105
})
141106

142107
describe("updateGlobalState", () => {
@@ -150,33 +115,6 @@ describe("ContextProxy", () => {
150115
const storedValue = await proxy.getGlobalState("apiProvider")
151116
expect(storedValue).toBe("deepseek")
152117
})
153-
154-
it("should bypass cache for pass-through state keys", async () => {
155-
const historyItems = [
156-
{
157-
id: "1",
158-
number: 1,
159-
ts: 1,
160-
task: "test",
161-
tokensIn: 1,
162-
tokensOut: 1,
163-
totalCost: 1,
164-
},
165-
]
166-
167-
await proxy.updateGlobalState("taskHistory", historyItems)
168-
169-
// Should update original context
170-
expect(mockGlobalState.update).toHaveBeenCalledWith("taskHistory", historyItems)
171-
172-
// Setup mock for subsequent get
173-
mockGlobalState.get.mockReturnValue(historyItems)
174-
175-
// Should get fresh value from original context
176-
const storedValue = proxy.getGlobalState("taskHistory")
177-
expect(storedValue).toBe(historyItems)
178-
expect(mockGlobalState.get).toHaveBeenCalledWith("taskHistory")
179-
})
180118
})
181119

182120
describe("getSecret", () => {

src/core/task/__tests__/Task.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,6 @@ describe("Cline", () => {
198198
mockExtensionContext = {
199199
globalState: {
200200
get: vi.fn().mockImplementation((key: keyof GlobalState) => {
201-
if (key === "taskHistory") {
202-
return [
203-
{
204-
id: "123",
205-
number: 0,
206-
ts: Date.now(),
207-
task: "historical task",
208-
tokensIn: 100,
209-
tokensOut: 200,
210-
cacheWrites: 0,
211-
cacheReads: 0,
212-
totalCost: 0.001,
213-
},
214-
]
215-
}
216-
217201
return undefined
218202
}),
219203
update: vi.fn().mockImplementation((_key, _value) => Promise.resolve()),

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npx vitest core/webview/__tests__/ClineProvider.spec.ts
22

3-
import { afterAll, vi, describe, test, it, expect, beforeEach } from "vitest"
3+
import { describe, test, expect, beforeEach, afterEach, afterAll, vi, it } from "vitest"
44
import Anthropic from "@anthropic-ai/sdk"
55
import * as vscode from "vscode"
66
import axios from "axios"
@@ -21,6 +21,20 @@ import { ClineProvider } from "../ClineProvider"
2121
// Mock setup must come before imports
2222
vi.mock("../../prompts/sections/custom-instructions")
2323

24+
// Mock extension context
25+
vi.mock("../../../extension", () => ({
26+
getExtensionContext: vi.fn().mockReturnValue({
27+
globalStorageUri: { fsPath: "/mock/storage/path" },
28+
}),
29+
}))
30+
31+
// Mock task history module
32+
vi.mock("../../task-persistence/taskHistory", () => ({
33+
getHistoryItem: vi.fn().mockResolvedValue(undefined),
34+
setHistoryItems: vi.fn().mockResolvedValue(undefined),
35+
deleteHistoryItem: vi.fn().mockResolvedValue(undefined),
36+
}))
37+
2438
vi.mock("vscode")
2539

2640
vi.mock("p-wait-for", () => ({
@@ -148,6 +162,7 @@ vi.mock("vscode", () => ({
148162
showInformationMessage: vi.fn(),
149163
showWarningMessage: vi.fn(),
150164
showErrorMessage: vi.fn(),
165+
createTextEditorDecorationType: vi.fn().mockReturnValue({}),
151166
},
152167
workspace: {
153168
getConfiguration: vi.fn().mockReturnValue({
@@ -501,7 +516,6 @@ describe("ClineProvider", () => {
501516
const mockState: ExtensionState = {
502517
version: "1.0.0",
503518
clineMessages: [],
504-
taskHistory: [],
505519
shouldShowAnnouncement: false,
506520
apiConfiguration: {
507521
apiProvider: "openrouter",
@@ -736,7 +750,7 @@ describe("ClineProvider", () => {
736750
expect(state).toHaveProperty("alwaysAllowWrite")
737751
expect(state).toHaveProperty("alwaysAllowExecute")
738752
expect(state).toHaveProperty("alwaysAllowBrowser")
739-
expect(state).toHaveProperty("taskHistory")
753+
// taskHistory has been deprecated and removed from the global state
740754
expect(state).toHaveProperty("soundEnabled")
741755
expect(state).toHaveProperty("ttsEnabled")
742756
expect(state).toHaveProperty("diffEnabled")

src/core/webview/__tests__/webviewMessageHandler.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ vi.mock("vscode", () => ({
4343
window: {
4444
showInformationMessage: vi.fn(),
4545
showErrorMessage: vi.fn(),
46+
createTextEditorDecorationType: vi.fn(() => ({
47+
key: "mock-decoration-type",
48+
})),
4649
},
4750
workspace: {
4851
workspaceFolders: [{ uri: { fsPath: "/mock/workspace" } }],
4952
},
53+
CodeActionKind: {
54+
QuickFix: "QuickFix",
55+
RefactorRewrite: "RefactorRewrite",
56+
},
5057
}))
5158

5259
vi.mock("../../../i18n", () => ({

webview-ui/src/components/chat/__tests__/ChatTextArea.spec.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defaultModeSlug } from "@roo/modes"
55
import { useExtensionState } from "@src/context/ExtensionStateContext"
66
import { vscode } from "@src/utils/vscode"
77
import * as pathMentions from "@src/utils/path-mentions"
8+
import { useTaskSearch } from "@src/components/history/useTaskSearch"
89

910
import ChatTextArea from "../ChatTextArea"
1011

@@ -16,6 +17,12 @@ vi.mock("@src/utils/vscode", () => ({
1617

1718
vi.mock("@src/components/common/CodeBlock")
1819
vi.mock("@src/components/common/MarkdownBlock")
20+
vi.mock("@src/components/history/useTaskSearch", () => ({
21+
useTaskSearch: vi.fn().mockReturnValue({
22+
tasks: [],
23+
loading: false,
24+
}),
25+
}))
1926
vi.mock("@src/utils/path-mentions", () => ({
2027
convertToMentionPath: vi.fn((path, cwd) => {
2128
// Simple mock implementation that mimics the real function's behavior
@@ -737,19 +744,23 @@ describe("ChatTextArea", () => {
737744
})
738745

739746
it("should use task history (oldest first) when no conversation messages exist", () => {
740-
const mockTaskHistory = [
741-
{ task: "First task", workspace: "/test/workspace" },
742-
{ task: "Second task", workspace: "/test/workspace" },
743-
{ task: "Third task", workspace: "/test/workspace" },
747+
const mockTaskItems = [
748+
{ id: "1", task: "First task", workspace: "/test/workspace", ts: 1000 },
749+
{ id: "2", task: "Second task", workspace: "/test/workspace", ts: 2000 },
750+
{ id: "3", task: "Third task", workspace: "/test/workspace", ts: 3000 },
744751
]
745752

753+
// Mock useTaskSearch to return the task items
754+
vi.mocked(useTaskSearch).mockReturnValue({
755+
tasks: mockTaskItems,
756+
loading: false,
757+
} as any)
746758
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
747759
filePaths: [],
748760
openedTabs: [],
749761
apiConfiguration: {
750762
apiProvider: "anthropic",
751763
},
752-
taskHistory: mockTaskHistory,
753764
clineMessages: [], // No conversation messages
754765
cwd: "/test/workspace",
755766
})
@@ -777,16 +788,20 @@ describe("ChatTextArea", () => {
777788
)
778789

779790
// Start with task history
791+
// Mock useTaskSearch to return the task items
792+
vi.mocked(useTaskSearch).mockReturnValue({
793+
tasks: [
794+
{ id: "1", task: "Task 1", workspace: "/test/workspace", ts: 1000 },
795+
{ id: "2", task: "Task 2", workspace: "/test/workspace", ts: 2000 },
796+
],
797+
loading: false,
798+
} as any)
780799
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
781800
filePaths: [],
782801
openedTabs: [],
783802
apiConfiguration: {
784803
apiProvider: "anthropic",
785804
},
786-
taskHistory: [
787-
{ task: "Task 1", workspace: "/test/workspace" },
788-
{ task: "Task 2", workspace: "/test/workspace" },
789-
],
790805
clineMessages: [],
791806
cwd: "/test/workspace",
792807
})
@@ -800,6 +815,11 @@ describe("ChatTextArea", () => {
800815
expect(setInputValue).toHaveBeenCalledWith("Task 1")
801816

802817
// Switch to conversation messages
818+
// Reset the useTaskSearch mock
819+
vi.mocked(useTaskSearch).mockReturnValue({
820+
tasks: [],
821+
loading: false,
822+
} as any)
803823
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
804824
filePaths: [],
805825
openedTabs: [],

webview-ui/src/components/history/__tests__/HistoryPreview.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("HistoryPreview", () => {
107107

108108
it("renders up to 3 tasks when tasks are available", () => {
109109
mockUseTaskSearch.mockReturnValue({
110-
tasks: mockTasks,
110+
tasks: mockTasks.slice(0, 3),
111111
loading: false,
112112
searchQuery: "",
113113
setSearchQuery: vi.fn(),

0 commit comments

Comments
 (0)