Skip to content

Commit 628b913

Browse files
test(webview): restore the invalid-mode case the 64ce56b merge dropped
The 64ce56b merge of upstream/main into vps2/f5-api-wiring dropped nine upstream titles. Seven of them reappear on this branch under branch-side names, and one - reads the current mode from the task when provider state differs in src/core/tools/__tests__/switchModeTool.spec.ts - is covered by should read the current mode from task.getTaskMode, not provider state, which asserts the same thing more strictly (it pins getTaskMode to one call and passes the task to handleModeSwitch). The remaining title, should handle invalid mode gracefully in src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts, came back with nothing behind it. The upstream body asserted that handleModeSwitch writes an unknown slug through to storage. That is false on this head: handleModeSwitch resolves the slug through getModeBySlug and returns before queueing the mutation when it is unknown (ClineProvider.ts:2648-2653), so the branch contract is the opposite - an unknown mode is logged and ignored. The restored case asserts that contract: the task mode does not move, no mode-switch event is emitted, no task history write happens, no mode write for the unknown slug reaches globalState, and the ignore line names the slug. Control run for the new case: disabling the slug-validation gate so the switch proceeds moves the task mode to not-a-mode and the case fails with expected not-a-mode to be code; with the gate restored it passes. Baseline whole ClineProvider.sticky-mode.spec.ts before the change was 47 passed, after it 48 passed. switchModeTool 18 passed, extension api specs and core/task-persistence lanes reported above, tsc -p tsconfig.json clean, eslint --prune-suppressions --max-warnings=0 clean with eslint-suppressions.json left untouched, prettier --check clean. Made with --no-verify because the pre-commit hook shells out to pnpm, which this lane has no PATH for; the gates above are what was actually run.
1 parent 0f5cfcc commit 628b913

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TelemetryService } from "@roo-code/telemetry"
77
import { ClineProvider } from "../ClineProvider"
88
import { ContextProxy } from "../../config/ContextProxy"
99
import { Task } from "../../task/Task"
10+
import type { Mode } from "../../../shared/modes"
1011
import type { HistoryItem } from "@roo-code/types"
1112
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
1213

@@ -1186,6 +1187,31 @@ describe("ClineProvider - Sticky Mode", () => {
11861187
expect(mockTask["_taskMode"]).toBe("architect")
11871188
expect(mockContext.globalState.update).toHaveBeenCalledWith("mode", "architect")
11881189
})
1190+
1191+
it("should handle invalid mode gracefully", async () => {
1192+
// Restores the case the 64ce56bfb merge of upstream/main dropped without a substitute.
1193+
// Upstream asserted the opposite of this branch: there, handleModeSwitch wrote the
1194+
// unknown slug straight through to storage. Here the slug is resolved through
1195+
// getModeBySlug first and an unknown one returns before the mutation is queued, so the
1196+
// contract is that an unknown mode is ignored and nothing about the current mode moves.
1197+
const { getModeBySlug } = await import("../../../shared/modes")
1198+
vi.mocked(getModeBySlug).mockReturnValue(undefined)
1199+
1200+
const mockTask = createModeSwitchTask()
1201+
const updateTaskHistorySpy = vi.spyOn(provider, "updateTaskHistory").mockImplementation(() => {
1202+
return Promise.resolve([])
1203+
})
1204+
1205+
await provider.handleModeSwitch("not-a-mode" as Mode, mockTask)
1206+
1207+
expect(mockTask["_taskMode"]).toBe("code")
1208+
expect(mockTask.emit).not.toHaveBeenCalled()
1209+
expect(updateTaskHistorySpy).not.toHaveBeenCalled()
1210+
expect(mockContext.globalState.update).not.toHaveBeenCalledWith("mode", "not-a-mode")
1211+
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(
1212+
expect.stringContaining('ignoring unknown mode "not-a-mode"'),
1213+
)
1214+
})
11891215
})
11901216

11911217
describe("createTaskWithHistoryItem", () => {

0 commit comments

Comments
 (0)