Skip to content

Commit 73fe9d8

Browse files
taltasclaude
andcommitted
test(cli): add coverage for autonomous mode functionality
Add tests for new autonomous mode features: - Extension host autonomous initialization and environment setup - Autonomous mode settings validation (orchestrator mode, auto-approval) - Root task tracking accessors (getLastTaskResult, getRootTaskId) - ROO_CLI_AUTONOMOUS environment variable management - Cancel task method These tests increase patch coverage for the autonomous CLI changes to meet the 80% codecov threshold. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b97b6c7 commit 73fe9d8

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

apps/cli/src/agent/__tests__/extension-host.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,4 +937,71 @@ describe("ExtensionHost", () => {
937937
expect(getPrivate(host, "ephemeralStorageDir")).toBeNull()
938938
})
939939
})
940+
941+
describe("autonomous mode", () => {
942+
it("should set ROO_CLI_AUTONOMOUS environment variable when autonomous is true", () => {
943+
const originalValue = process.env.ROO_CLI_AUTONOMOUS
944+
945+
const host = createTestHost({ autonomous: true })
946+
947+
expect(process.env.ROO_CLI_AUTONOMOUS).toBe("1")
948+
949+
// Cleanup
950+
if (originalValue === undefined) {
951+
delete process.env.ROO_CLI_AUTONOMOUS
952+
} else {
953+
process.env.ROO_CLI_AUTONOMOUS = originalValue
954+
}
955+
})
956+
957+
it("should not set ROO_CLI_AUTONOMOUS when autonomous is false", () => {
958+
const originalValue = process.env.ROO_CLI_AUTONOMOUS
959+
delete process.env.ROO_CLI_AUTONOMOUS
960+
961+
const host = createTestHost({ autonomous: false })
962+
963+
expect(process.env.ROO_CLI_AUTONOMOUS).toBeUndefined()
964+
965+
// Cleanup
966+
if (originalValue !== undefined) {
967+
process.env.ROO_CLI_AUTONOMOUS = originalValue
968+
}
969+
})
970+
971+
it("should force orchestrator mode when autonomous is true", () => {
972+
const host = createTestHost({ mode: "code", autonomous: true })
973+
const initialSettings = getPrivate(host, "initialSettings")
974+
975+
expect(initialSettings.mode).toBe("orchestrator")
976+
})
977+
978+
it("should enable auto-approval for autonomous mode", () => {
979+
const host = createTestHost({ autonomous: true })
980+
const initialSettings = getPrivate(host, "initialSettings")
981+
982+
expect(initialSettings.autoApprovalEnabled).toBe(true)
983+
expect(initialSettings.alwaysAllowReadOnly).toBe(true)
984+
expect(initialSettings.alwaysAllowWrite).toBe(true)
985+
expect(initialSettings.alwaysAllowMcp).toBe(true)
986+
})
987+
988+
it("should store last task result", () => {
989+
const host = createTestHost()
990+
991+
expect(host.getLastTaskResult()).toBeUndefined()
992+
})
993+
994+
it("should store root task ID", () => {
995+
const host = createTestHost()
996+
997+
expect(host.getRootTaskId()).toBeUndefined()
998+
})
999+
1000+
it("should expose cancelTask method", async () => {
1001+
const host = createTestHost()
1002+
1003+
// Should not throw even if extension API is not ready
1004+
await expect(host.cancelTask()).resolves.toBeUndefined()
1005+
})
1006+
})
9401007
})

apps/cli/src/agent/__tests__/json-event-emitter-result.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ClineMessage } from "@roo-code/types"
22
import { Writable } from "stream"
3+
import { vi } from "vitest"
34

45
import type { TaskCompletedEvent } from "../events.js"
56
import { JsonEventEmitter } from "../json-event-emitter.js"
@@ -87,6 +88,8 @@ describe("JsonEventEmitter result emission", () => {
8788
])
8889
})
8990

91+
92+
9093
it("uses the terminal discriminator for aggregate JSON output", () => {
9194
const { stdout, content } = createMockStdout()
9295
const emitter = new JsonEventEmitter({ mode: "json", stdout, authoritativeCompletion: true })

0 commit comments

Comments
 (0)