Skip to content

Commit 5566162

Browse files
roomoteedelauna
authored andcommitted
test: tighten switch mode review feedback cases
1 parent 43714e1 commit 5566162

1 file changed

Lines changed: 7 additions & 31 deletions

File tree

src/core/tools/__tests__/switchModeTool.spec.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ vi.mock("../../../shared/modes", async (importOriginal) => {
1717
return {
1818
...actual,
1919
defaultModeSlug: "code",
20-
getModeBySlug: vi.fn((slug: string, _customModes?: unknown[]) => {
20+
getModeBySlug: vi.fn((slug: string, customModes?: Array<{ slug: string; name: string }>) => {
2121
const builtInModes: Record<string, { slug: string; name: string }> = {
2222
code: { slug: "code", name: "Code" },
2323
architect: { slug: "architect", name: "Architect" },
2424
ask: { slug: "ask", name: "Ask" },
25-
"custom-mode": { slug: "custom-mode", name: "Custom Mode" },
2625
}
27-
return builtInModes[slug]
26+
return customModes?.find((mode) => mode.slug === slug) ?? builtInModes[slug]
2827
}),
2928
}
3029
})
@@ -200,34 +199,6 @@ describe("SwitchModeTool", () => {
200199
expect(mockTask.consecutiveMistakeCount).toBe(0)
201200
})
202201

203-
// ===== Edge case: providerRef is null =====
204-
205-
it("should proceed silently when providerRef deref returns undefined", async () => {
206-
mockTask = {
207-
...mockTask,
208-
providerRef: {
209-
deref: vi.fn().mockReturnValue(undefined),
210-
},
211-
} as unknown as Task
212-
213-
const block = createBlock({ mode_slug: "architect", reason: "test" })
214-
215-
// When deref returns undefined, optional chaining makes getState() and
216-
// handleModeSwitch() no-ops. getModeBySlug still returns a valid mode,
217-
// and currentMode falls back to defaultModeSlug. The tool proceeds
218-
// without throwing — but the mode switch is a no-op.
219-
await switchModeTool.handle(mockTask, block, mockCallbacks)
220-
221-
// Should NOT call handleError (no exception thrown)
222-
expect(mockCallbacks.handleError).not.toHaveBeenCalled()
223-
// Should have asked for approval
224-
expect(mockCallbacks.askApproval).toHaveBeenCalled()
225-
// Should still push a success result (even though switch was a no-op)
226-
expect(mockCallbacks.pushToolResult).toHaveBeenCalledWith(
227-
"Successfully switched from Code mode to Architect mode because: test.",
228-
)
229-
})
230-
231202
// ===== Edge case: getState throws an error =====
232203

233204
it("should handle getState throwing an error", async () => {
@@ -322,6 +293,11 @@ describe("SwitchModeTool", () => {
322293
// ===== Custom mode support =====
323294

324295
it("should switch to a custom mode", async () => {
296+
mockGetState.mockResolvedValue({
297+
mode: "code",
298+
customModes: [{ slug: "custom-mode", name: "Custom Mode" }],
299+
})
300+
325301
const block = createBlock({ mode_slug: "custom-mode", reason: "testing custom modes" })
326302

327303
await switchModeTool.handle(mockTask, block, mockCallbacks)

0 commit comments

Comments
 (0)