Skip to content

Commit 4adee96

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 22b38d2 commit 4adee96

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(),
@@ -973,6 +979,16 @@ describe("Cline", () => {
973979
startTask: false,
974980
})
975981

982+
// Initialize child messages
983+
child.clineMessages = [
984+
{
985+
ts: Date.now(),
986+
type: "say",
987+
say: "api_req_started",
988+
text: "Preparing request...",
989+
},
990+
]
991+
976992
// Mock the child's API stream
977993
const childMockStream = {
978994
async *[Symbol.asyncIterator]() {
@@ -1105,6 +1121,16 @@ describe("Cline", () => {
11051121

11061122
vi.spyOn(child1.api, "createMessage").mockReturnValue(mockStream)
11071123

1124+
// Initialize with a starting message
1125+
child1.clineMessages = [
1126+
{
1127+
ts: Date.now(),
1128+
type: "say",
1129+
say: "api_req_started",
1130+
text: "Preparing request...",
1131+
},
1132+
]
1133+
11081134
// Make an API request with the first child task
11091135
const child1Iterator = child1.attemptApiRequest(0)
11101136
await child1Iterator.next()
@@ -1128,6 +1154,16 @@ describe("Cline", () => {
11281154

11291155
vi.spyOn(child2.api, "createMessage").mockReturnValue(mockStream)
11301156

1157+
// Initialize with a starting message
1158+
child2.clineMessages = [
1159+
{
1160+
ts: Date.now(),
1161+
type: "say",
1162+
say: "api_req_started",
1163+
text: "Preparing request...",
1164+
},
1165+
]
1166+
11311167
// Make an API request with the second child task
11321168
const child2Iterator = child2.attemptApiRequest(0)
11331169
await child2Iterator.next()

0 commit comments

Comments
 (0)