Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 24 additions & 3 deletions cli/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import { config } from "@roo-code/config-eslint/base"
import js from "@eslint/js"
import eslintConfigPrettier from "eslint-config-prettier"
import turboPlugin from "eslint-plugin-turbo"
import tseslint from "typescript-eslint"

export default [
...config,
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
{
plugins: {
turbo: turboPlugin,
},
rules: {
"turbo/no-undeclared-env-vars": "off",
},
},
{
rules: {
// "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-explicit-any": "error",
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
}
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"@roo-code/config-eslint": "workspace:^",
"@roo-code/config-typescript": "workspace:^",
"@types/fs-extra": "^11.0.4",
Expand All @@ -156,12 +157,15 @@
"@types/semver": "^7.5.8",
"cpy-cli": "^5.0.0",
"del-cli": "^5.1.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-turbo": "^2.4.4",
"ink-testing-library": "^4.0.0",
"mkdirp": "^3.0.1",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"tsx": "^4.19.3",
"typescript": "^5.4.5",
"typescript-eslint": "^8.26.0",
"vitest": "^3.2.3"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/__tests__/config-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vi.mock("fs/promises", async () => {
const actual = await vi.importActual<typeof import("fs/promises")>("fs/promises")
return {
...actual,
readFile: vi.fn(async (filePath: any, encoding?: any) => {
readFile: vi.fn(async (filePath: string | Buffer | URL, encoding?: BufferEncoding | null) => {
// If reading schema.json, return a minimal valid schema
if (typeof filePath === "string" && filePath.includes("schema.json")) {
return JSON.stringify({
Expand All @@ -21,7 +21,7 @@ vi.mock("fs/promises", async () => {
})
}
// Otherwise use the actual implementation
return actual.readFile(filePath, encoding)
return actual.readFile(filePath, encoding as BufferEncoding)
}),
}
})
Expand Down
4 changes: 2 additions & 2 deletions cli/src/__tests__/config-default-creation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vi.mock("fs/promises", async () => {
const actual = await vi.importActual<typeof import("fs/promises")>("fs/promises")
return {
...actual,
readFile: vi.fn(async (filePath: any, encoding?: any) => {
readFile: vi.fn(async (filePath: string | Buffer | URL, encoding?: BufferEncoding | null) => {
// If reading schema.json, return a minimal valid schema
if (typeof filePath === "string" && filePath.includes("schema.json")) {
return JSON.stringify({
Expand All @@ -30,7 +30,7 @@ vi.mock("fs/promises", async () => {
})
}
// Otherwise use the actual implementation
return actual.readFile(filePath, encoding)
return actual.readFile(filePath, encoding as BufferEncoding)
}),
}
})
Expand Down
4 changes: 2 additions & 2 deletions cli/src/__tests__/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for history persistence and navigation
*/

import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"
import { describe, it, expect, beforeEach, afterEach } from "vitest"
import * as fs from "fs/promises"
import * as path from "path"
import * as os from "os"
Expand Down Expand Up @@ -34,7 +34,7 @@ describe("History Persistence", () => {
// Clean up test directory
try {
await fs.rm(testDir, { recursive: true, force: true })
} catch (error) {
} catch (_error) {
// Ignore cleanup errors
}

Expand Down
44 changes: 5 additions & 39 deletions cli/src/commands/__tests__/clear.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,18 @@
* Tests for the /clear command
*/

import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"
import { describe, it, expect, beforeEach, vi } from "vitest"
import { clearCommand } from "../clear.js"
import type { CommandContext } from "../core/types.js"
import { createMockContext } from "./helpers/mockContext.js"

describe("clearCommand", () => {
let mockContext: CommandContext

beforeEach(() => {
mockContext = {
mockContext = createMockContext({
input: "/clear",
args: [],
options: {},
sendMessage: vi.fn().mockResolvedValue(undefined),
addMessage: vi.fn(),
clearMessages: vi.fn(),
replaceMessages: vi.fn(),
setMessageCutoffTimestamp: vi.fn(),
clearTask: vi.fn().mockResolvedValue(undefined),
setMode: vi.fn(),
exit: vi.fn(),
routerModels: null,
currentProvider: null,
kilocodeDefaultModel: "",
updateProviderModel: vi.fn().mockResolvedValue(undefined),
refreshRouterModels: vi.fn().mockResolvedValue(undefined),
updateProvider: vi.fn().mockResolvedValue(undefined),
profileData: null,
balanceData: null,
profileLoading: false,
balanceLoading: false,
refreshTerminal: vi.fn().mockResolvedValue(undefined),
taskHistoryData: null,
taskHistoryFilters: {
workspace: "current",
sort: "newest",
favoritesOnly: false,
},
taskHistoryLoading: false,
taskHistoryError: null,
fetchTaskHistory: vi.fn().mockResolvedValue(undefined),
updateTaskHistoryFilters: vi.fn().mockResolvedValue(null),
changeTaskHistoryPage: vi.fn().mockResolvedValue(null),
nextTaskHistoryPage: vi.fn().mockResolvedValue(null),
previousTaskHistoryPage: vi.fn().mockResolvedValue(null),
sendWebviewMessage: vi.fn().mockResolvedValue(undefined),
}
})
})

describe("command metadata", () => {
Expand Down Expand Up @@ -87,7 +53,7 @@ describe("clearCommand", () => {
const afterTime = Date.now()

expect(mockContext.setMessageCutoffTimestamp).toHaveBeenCalledTimes(1)
const timestamp = (mockContext.setMessageCutoffTimestamp as any).mock.calls[0][0]
const timestamp = (mockContext.setMessageCutoffTimestamp as ReturnType<typeof vi.fn>).mock.calls[0][0]
expect(timestamp).toBeGreaterThanOrEqual(beforeTime)
expect(timestamp).toBeLessThanOrEqual(afterTime)
})
Expand Down
23 changes: 3 additions & 20 deletions cli/src/commands/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"
import { configCommand } from "../config.js"
import type { CommandContext } from "../core/types.js"
import openConfigFile from "../../config/openConfig.js"
import { createMockContext } from "./helpers/mockContext.js"

// Mock the openConfigFile function
vi.mock("../../config/openConfig.js", () => ({
Expand All @@ -16,28 +17,10 @@ describe("configCommand", () => {
vi.clearAllMocks()
addMessageSpy = vi.fn()

mockContext = {
mockContext = createMockContext({
input: "/config",
args: [],
options: {},
sendMessage: vi.fn(),
addMessage: addMessageSpy,
clearMessages: vi.fn(),
replaceMessages: vi.fn(),
clearTask: vi.fn(),
setMode: vi.fn(),
exit: vi.fn(),
routerModels: null,
currentProvider: null,
kilocodeDefaultModel: "",
updateProviderModel: vi.fn(),
refreshRouterModels: vi.fn(),
updateProvider: vi.fn(),
profileData: null,
balanceData: null,
profileLoading: false,
balanceLoading: false,
}
})
})

it("should have correct metadata", () => {
Expand Down
77 changes: 77 additions & 0 deletions cli/src/commands/__tests__/helpers/mockContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Test helper for creating mock CommandContext
*
* This utility provides a reusable mock context for command tests,
* eliminating the need to duplicate the same mock setup across multiple test files.
*
* @example
* ```typescript
* import { createMockContext } from "./helpers/mockContext.js"
*
* const mockContext = createMockContext({
* input: "/clear",
* addMessage: vi.fn(),
* })
* ```
*/

import { vi } from "vitest"
import type { CommandContext } from "../../core/types.js"
import type { CLIConfig } from "../../../config/types.js"

/**
* Creates a mock CommandContext with all required properties.
* All functions are mocked with vi.fn() and return appropriate default values.
*
* @param overrides - Partial context to override default values
* @returns A complete mock CommandContext with all required properties
*/
export function createMockContext(overrides: Partial<CommandContext> = {}): CommandContext {
const defaultContext: CommandContext = {
input: "",
args: [],
options: {},
config: {} as CLIConfig,
sendMessage: vi.fn().mockResolvedValue(undefined),
addMessage: vi.fn(),
clearMessages: vi.fn(),
replaceMessages: vi.fn(),
setMessageCutoffTimestamp: vi.fn(),
clearTask: vi.fn().mockResolvedValue(undefined),
setMode: vi.fn(),
setTheme: vi.fn().mockResolvedValue(undefined),
exit: vi.fn(),
setCommittingParallelMode: vi.fn(),
isParallelMode: false,
routerModels: null,
currentProvider: null,
kilocodeDefaultModel: "",
updateProviderModel: vi.fn().mockResolvedValue(undefined),
refreshRouterModels: vi.fn().mockResolvedValue(undefined),
updateProvider: vi.fn().mockResolvedValue(undefined),
profileData: null,
balanceData: null,
profileLoading: false,
balanceLoading: false,
refreshTerminal: vi.fn().mockResolvedValue(undefined),
taskHistoryData: null,
taskHistoryFilters: {
workspace: "current",
sort: "newest",
favoritesOnly: false,
},
taskHistoryLoading: false,
taskHistoryError: null,
fetchTaskHistory: vi.fn().mockResolvedValue(undefined),
updateTaskHistoryFilters: vi.fn().mockResolvedValue(null),
changeTaskHistoryPage: vi.fn().mockResolvedValue(null),
nextTaskHistoryPage: vi.fn().mockResolvedValue(null),
previousTaskHistoryPage: vi.fn().mockResolvedValue(null),
sendWebviewMessage: vi.fn().mockResolvedValue(undefined),
}

return {
...defaultContext,
...overrides,
}
}
28 changes: 22 additions & 6 deletions cli/src/commands/__tests__/model.autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { describe, it, expect, beforeEach } from "vitest"
import { getArgumentSuggestions } from "../../services/autocomplete.js"
import type { RouterModels } from "../../types/messages.js"
import type { ProviderConfig } from "../../config/types.js"
import type { ArgumentProviderContext } from "../core/types.js"

describe("Model Command Autocomplete", () => {
let mockCommandContext: any
let mockCommandContext: Partial<ArgumentProviderContext["commandContext"]>

beforeEach(() => {
// Mock command context with router models
Expand Down Expand Up @@ -71,7 +72,10 @@ describe("Model Command Autocomplete", () => {
// multi-argument commands. The fix works in the real application where
// autocomplete is triggered through the UI differently.
const input = "/model select gpt"
const suggestions = await getArgumentSuggestions(input, mockCommandContext)
const suggestions = await getArgumentSuggestions(
input,
mockCommandContext as ArgumentProviderContext["commandContext"],
)

expect(suggestions).toBeDefined()
expect(suggestions.length).toBeGreaterThan(0)
Expand All @@ -86,7 +90,10 @@ describe("Model Command Autocomplete", () => {
// multi-argument commands. The fix works in the real application where
// autocomplete is triggered through the UI differently.
const input = "/model select "
const suggestions = await getArgumentSuggestions(input, mockCommandContext)
const suggestions = await getArgumentSuggestions(
input,
mockCommandContext as ArgumentProviderContext["commandContext"],
)

expect(suggestions).toBeDefined()
expect(suggestions.length).toBe(3) // All 3 mock models
Expand All @@ -97,7 +104,10 @@ describe("Model Command Autocomplete", () => {
// multi-argument commands. The fix works in the real application where
// autocomplete is triggered through the UI differently.
const input = "/model select claude"
const suggestions = await getArgumentSuggestions(input, mockCommandContext)
const suggestions = await getArgumentSuggestions(
input,
mockCommandContext as ArgumentProviderContext["commandContext"],
)

expect(suggestions).toBeDefined()
expect(suggestions.length).toBeGreaterThan(0)
Expand All @@ -121,7 +131,10 @@ describe("Model Command Autocomplete", () => {
...mockCommandContext,
currentProvider: null,
}
const suggestions = await getArgumentSuggestions(input, contextWithoutProvider)
const suggestions = await getArgumentSuggestions(
input,
contextWithoutProvider as ArgumentProviderContext["commandContext"],
)

expect(suggestions).toBeDefined()
expect(suggestions.length).toBe(0)
Expand All @@ -133,7 +146,10 @@ describe("Model Command Autocomplete", () => {
...mockCommandContext,
routerModels: null,
}
const suggestions = await getArgumentSuggestions(input, contextWithoutModels)
const suggestions = await getArgumentSuggestions(
input,
contextWithoutModels as ArgumentProviderContext["commandContext"],
)

expect(suggestions).toBeDefined()
expect(suggestions.length).toBe(0)
Expand Down
Loading