Skip to content

Commit ae5f97d

Browse files
author
Eric Wheeler
committed
test: add safeWriteJson mock for transactional file operations
- Add vitest imports and mock safeWriteJson to support atomic transaction testing. This ensures file operations in tests are properly isolated and can be verified without actual filesystem interactions. - Add fs/promises.access mock to prevent errors when checking file existence. - Satisfy requirement that clineMessages must be defined for say/ask() to be valid Signed-off-by: Eric Wheeler <[email protected]>
1 parent 757a483 commit ae5f97d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from "path"
55

66
import * as vscode from "vscode"
77
import { Anthropic } from "@anthropic-ai/sdk"
8+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
89

910
import type { GlobalState, ProviderSettings, ModelInfo } from "@roo-code/types"
1011
import { TelemetryService } from "@roo-code/telemetry"
@@ -59,6 +60,7 @@ vi.mock("fs/promises", async (importOriginal) => {
5960
}),
6061
unlink: vi.fn().mockResolvedValue(undefined),
6162
rmdir: vi.fn().mockResolvedValue(undefined),
63+
access: vi.fn().mockResolvedValue(undefined),
6264
}
6365

6466
return {
@@ -164,6 +166,10 @@ vi.mock("../../../utils/fs", () => ({
164166
}),
165167
}))
166168

169+
vi.mock("../../../utils/safeWriteJson", () => ({
170+
safeWriteJson: vi.fn().mockResolvedValue(undefined),
171+
}))
172+
167173
const mockMessages = [
168174
{
169175
ts: Date.now(),
@@ -1037,6 +1043,16 @@ describe("Cline", () => {
10371043
startTask: false,
10381044
})
10391045

1046+
// Initialize child messages
1047+
child.clineMessages = [
1048+
{
1049+
ts: Date.now(),
1050+
type: "say",
1051+
say: "api_req_started",
1052+
text: "Preparing request...",
1053+
},
1054+
]
1055+
10401056
// Mock the child's API stream
10411057
const childMockStream = {
10421058
async *[Symbol.asyncIterator]() {
@@ -1169,6 +1185,16 @@ describe("Cline", () => {
11691185

11701186
vi.spyOn(child1.api, "createMessage").mockReturnValue(mockStream)
11711187

1188+
// Initialize with a starting message
1189+
child1.clineMessages = [
1190+
{
1191+
ts: Date.now(),
1192+
type: "say",
1193+
say: "api_req_started",
1194+
text: "Preparing request...",
1195+
},
1196+
]
1197+
11721198
// Make an API request with the first child task
11731199
const child1Iterator = child1.attemptApiRequest(0)
11741200
await child1Iterator.next()
@@ -1192,6 +1218,16 @@ describe("Cline", () => {
11921218

11931219
vi.spyOn(child2.api, "createMessage").mockReturnValue(mockStream)
11941220

1221+
// Initialize with a starting message
1222+
child2.clineMessages = [
1223+
{
1224+
ts: Date.now(),
1225+
type: "say",
1226+
say: "api_req_started",
1227+
text: "Preparing request...",
1228+
},
1229+
]
1230+
11951231
// Make an API request with the second child task
11961232
const child2Iterator = child2.attemptApiRequest(0)
11971233
await child2Iterator.next()

0 commit comments

Comments
 (0)