Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/config/CustomModesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ModeConfig } from "../../shared/modes"
import { fileExistsAtPath } from "../../utils/fs"
import { arePathsEqual, getWorkspacePath } from "../../utils/path"
import { logger } from "../../utils/logging"
import { GlobalFileNames } from "../../shared/globalFileNames"

const ROOMODES_FILENAME = ".roomodes"

Expand Down Expand Up @@ -113,7 +114,7 @@ export class CustomModesManager {

async getCustomModesFilePath(): Promise<string> {
const settingsDir = await this.ensureSettingsDirectoryExists()
const filePath = path.join(settingsDir, "cline_custom_modes.json")
const filePath = path.join(settingsDir, GlobalFileNames.customModes)
const fileExists = await fileExistsAtPath(filePath)
if (!fileExists) {
await this.queueWrite(async () => {
Expand Down
14 changes: 7 additions & 7 deletions src/core/config/__tests__/CustomModesManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CustomModesManager } from "../CustomModesManager"
import { ModeConfig } from "../../../shared/modes"
import { fileExistsAtPath } from "../../../utils/fs"
import { getWorkspacePath, arePathsEqual } from "../../../utils/path"
import { GlobalFileNames } from "../../../shared/globalFileNames"

jest.mock("vscode")
jest.mock("fs/promises")
Expand All @@ -21,7 +22,7 @@ describe("CustomModesManager", () => {

// Use path.sep to ensure correct path separators for the current platform
const mockStoragePath = `${path.sep}mock${path.sep}settings`
const mockSettingsPath = path.join(mockStoragePath, "settings", "cline_custom_modes.json")
const mockSettingsPath = path.join(mockStoragePath, "settings", GlobalFileNames.customModes)
const mockRoomodes = `${path.sep}mock${path.sep}workspace${path.sep}.roomodes`

beforeEach(() => {
Expand Down Expand Up @@ -333,17 +334,16 @@ describe("CustomModesManager", () => {
expect(mockOnUpdate).toHaveBeenCalled()
})
})

describe("File Operations", () => {
it("creates settings directory if it doesn't exist", async () => {
const configPath = path.join(mockStoragePath, "settings", "cline_custom_modes.json")
const settingsPath = path.join(mockStoragePath, "settings", GlobalFileNames.customModes)
await manager.getCustomModesFilePath()

expect(fs.mkdir).toHaveBeenCalledWith(path.dirname(configPath), { recursive: true })
expect(fs.mkdir).toHaveBeenCalledWith(path.dirname(settingsPath), { recursive: true })
})

it("creates default config if file doesn't exist", async () => {
const configPath = path.join(mockStoragePath, "settings", "cline_custom_modes.json")
const settingsPath = path.join(mockStoragePath, "settings", GlobalFileNames.customModes)

// Mock fileExists to return false first time, then true
let firstCall = true
Expand All @@ -358,13 +358,13 @@ describe("CustomModesManager", () => {
await manager.getCustomModesFilePath()

expect(fs.writeFile).toHaveBeenCalledWith(
configPath,
settingsPath,
expect.stringMatching(/^\{\s+"customModes":\s+\[\s*\]\s*\}$/),
)
})

it("watches file for changes", async () => {
const configPath = path.join(mockStoragePath, "settings", "cline_custom_modes.json")
const configPath = path.join(mockStoragePath, "settings", GlobalFileNames.customModes)

;(fs.readFile as jest.Mock).mockResolvedValue(JSON.stringify({ customModes: [] }))
;(arePathsEqual as jest.Mock).mockImplementation((path1: string, path2: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/globalFileNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const GlobalFileNames = {
glamaModels: "glama_models.json",
openRouterModels: "openrouter_models.json",
requestyModels: "requesty_models.json",
mcpSettings: "cline_mcp_settings.json",
mcpSettings: "mcp_settings.json",
unboundModels: "unbound_models.json",
customModes: "custom_modes.json",
}
Loading