-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathexecuteCommand.integration.spec.ts
More file actions
98 lines (84 loc) · 2.69 KB
/
executeCommand.integration.spec.ts
File metadata and controls
98 lines (84 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { randomUUID } from "crypto"
import * as os from "os"
import * as path from "path"
import * as fs from "fs/promises"
import { Task } from "../../task/Task"
import { executeCommandInTerminal } from "../ExecuteCommandTool"
describe("executeCommandInTerminal integration", () => {
it("returns promptly for explicit trailing background commands", async () => {
if (process.platform === "win32") {
return
}
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), "roo-execute-command-bg-"))
const taskId = `test-task-${randomUUID()}`
try {
const provider = {
postMessageToWebview: vitest.fn(),
getState: vitest.fn().mockResolvedValue({}),
context: undefined,
}
const task = {
cwd,
taskId,
providerRef: {
deref: vitest.fn().mockResolvedValue(provider),
},
say: vitest.fn().mockResolvedValue(undefined),
ask: vitest.fn(),
terminalProcess: undefined,
supersedePendingAsk: vitest.fn(),
} as unknown as Task
const startedAt = Date.now()
const [rejected, result] = await executeCommandInTerminal(task, {
executionId: "integration-bg-1",
command: "sleep 2 &",
terminalShellIntegrationDisabled: true,
})
const elapsedMs = Date.now() - startedAt
expect(rejected).toBe(false)
expect(elapsedMs).toBeLessThan(1_200)
expect(result).toContain("Command is still running in terminal")
} finally {
await fs.rm(cwd, { recursive: true, force: true })
}
})
it("does not treat mid-command backgrounding as explicit background execution", async () => {
if (process.platform === "win32") {
return
}
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), "roo-execute-command-mid-bg-"))
const taskId = `test-task-${randomUUID()}`
try {
const provider = {
postMessageToWebview: vitest.fn(),
getState: vitest.fn().mockResolvedValue({}),
context: undefined,
}
const task = {
cwd,
taskId,
providerRef: {
deref: vitest.fn().mockResolvedValue(provider),
},
say: vitest.fn().mockResolvedValue(undefined),
ask: vitest.fn(),
terminalProcess: undefined,
supersedePendingAsk: vitest.fn(),
} as unknown as Task
const startedAt = Date.now()
const [rejected, result] = await executeCommandInTerminal(task, {
executionId: "integration-bg-2",
command: "sleep 1 & sleep 1; echo done",
terminalShellIntegrationDisabled: true,
})
const elapsedMs = Date.now() - startedAt
expect(rejected).toBe(false)
expect(elapsedMs).toBeGreaterThan(700)
expect(result).toContain("Exit code: 0")
expect(result).toContain("done")
expect(result).not.toContain("Command is still running in terminal")
} finally {
await fs.rm(cwd, { recursive: true, force: true })
}
})
})