Skip to content

Commit 3e89aba

Browse files
committed
test(cli): cover run option resolution
1 parent 52e2322 commit 3e89aba

1 file changed

Lines changed: 80 additions & 1 deletion

File tree

‎apps/cli/src/commands/cli/__tests__/run.test.ts‎

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,42 @@ import path from "path"
33
import os from "os"
44

55
import { providerIdentifiers } from "@roo-code/types"
6-
import { DEFAULT_FLAGS } from "@/types/index.js"
6+
import { DEFAULT_FLAGS, FlagOptions } from "@/types/index.js"
77
import {
88
resolveLegacyRequireApproval,
99
resolveModel,
1010
resolveProvider,
1111
resolveReasoningEffort,
1212
resolveWorkspacePath,
13+
run,
1314
} from "../run.js"
1415

16+
const runCommandMocks = vi.hoisted(() => ({
17+
activate: vi.fn(async () => undefined),
18+
dispose: vi.fn(async () => undefined),
19+
loadSettings: vi.fn(),
20+
options: [] as unknown[],
21+
runTask: vi.fn(async () => undefined),
22+
}))
23+
24+
vi.mock("@/lib/storage/index.js", () => ({
25+
loadSettings: runCommandMocks.loadSettings,
26+
}))
27+
28+
vi.mock("@/agent/index.js", () => ({
29+
ExtensionHost: class {
30+
client = {}
31+
32+
constructor(options: unknown) {
33+
runCommandMocks.options.push(options)
34+
}
35+
36+
activate = runCommandMocks.activate
37+
dispose = runCommandMocks.dispose
38+
runTask = runCommandMocks.runTask
39+
},
40+
}))
41+
1542
describe("resolveModel", () => {
1643
it("uses the CLI flag before the settings model", () => {
1744
expect(resolveModel("flag-model", "settings-model")).toBe("flag-model")
@@ -69,6 +96,58 @@ describe("resolveLegacyRequireApproval", () => {
6996
)
7097
})
7198

99+
describe("run command option resolution", () => {
100+
let workspacePath: string
101+
102+
beforeEach(() => {
103+
vi.clearAllMocks()
104+
runCommandMocks.options.length = 0
105+
workspacePath = fs.mkdtempSync(path.join(os.tmpdir(), "roo-run-test-"))
106+
})
107+
108+
afterEach(() => {
109+
fs.rmSync(workspacePath, { recursive: true, force: true })
110+
vi.restoreAllMocks()
111+
})
112+
113+
it("passes resolved settings and workspace values to the extension host", async () => {
114+
runCommandMocks.loadSettings.mockResolvedValue({
115+
model: "settings-model",
116+
reasoningEffort: "high",
117+
provider: providerIdentifiers.anthropic,
118+
dangerouslySkipPermissions: false,
119+
})
120+
const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never)
121+
const flags: FlagOptions = {
122+
continue: false,
123+
workspace: path.relative(process.cwd(), workspacePath),
124+
print: true,
125+
stdinPromptStream: false,
126+
signalOnlyExit: false,
127+
debug: false,
128+
requireApproval: false,
129+
exitOnError: false,
130+
apiKey: "test-api-key",
131+
ephemeral: true,
132+
oneshot: false,
133+
}
134+
135+
await run("test prompt", flags)
136+
137+
expect(runCommandMocks.options).toEqual([
138+
expect.objectContaining({
139+
model: "settings-model",
140+
reasoningEffort: "high",
141+
provider: providerIdentifiers.anthropic,
142+
workspacePath,
143+
nonInteractive: false,
144+
}),
145+
])
146+
expect(runCommandMocks.runTask).toHaveBeenCalledWith("test prompt", undefined)
147+
expect(exitSpy).toHaveBeenCalledWith(0)
148+
})
149+
})
150+
72151
describe("run command --prompt-file option", () => {
73152
let tempDir: string
74153
let promptFilePath: string

0 commit comments

Comments
 (0)