Changesets · Branches · Tags · Compare
| Changeset | 5b5fa6eb4e4aa74696be1f85a06dfe712e34c0b3f4bd319241bf113bd718ff56 |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-23 10:32 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-23 10:32 -07:00 |
| Parents | 231e99760742 |
4 files changed
modified extensions/cli/src/commands/commands.ts +6 −1
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | export { chat } from "./chat.js"; |
| 5 | 5 | export { login } from "./login.js"; |
| 6 | 6 | export { logout } from "./logout.js"; |
| 7 | +export { listSessionsCommand } from "./ls.js"; | |
| 7 | 8 | export { remote } from "./remote.js"; |
| 8 | 9 | export { serve } from "./serve.js"; |
| 9 | -export { listSessionsCommand } from "./ls.js"; | |
| 10 | 10 | |
| 11 | 11 | export interface SlashCommand { |
| 12 | 12 | name: string; |
| @@ -45,6 +45,11 @@ | ||
| 45 | 45 | description: "Check who you're currently logged in as", |
| 46 | 46 | category: "system", |
| 47 | 47 | }, |
| 48 | + { | |
| 49 | + name: "info", | |
| 50 | + description: "Show session information", | |
| 51 | + category: "system", | |
| 52 | + }, | |
| 48 | 53 | { |
| 49 | 54 | name: "model", |
| 50 | 55 | description: "Switch between available chat models", |
modified extensions/cli/src/session.ts +1 −1
| @@ -180,7 +180,7 @@ | ||
| 180 | 180 | /** |
| 181 | 181 | * Get the session file path for the current session |
| 182 | 182 | */ |
| 183 | -function getSessionFilePath(): string { | |
| 183 | +export function getSessionFilePath(): string { | |
| 184 | 184 | const sessionId = getSessionId(); |
| 185 | 185 | const sessionDir = getSessionDir(); |
| 186 | 186 | return path.join(sessionDir, `${sessionId}.json`); |
modified extensions/cli/src/slashCommands.test.ts +160 −125
| @@ -1,147 +1,182 @@ | ||
| 1 | -// Import after mocking | |
| 2 | -import { AssistantUnrolled } from "@continuedev/config-yaml"; | |
| 3 | -import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | |
| 4 | - | |
| 5 | -import * as workos from "./auth/workos.js"; | |
| 6 | -import * as commands from "./commands/commands.js"; | |
| 7 | -import { reloadService, SERVICE_NAMES, services } from "./services/index.js"; | |
| 8 | -import type { AuthServiceState } from "./services/types.js"; | |
| 1 | +import type { AssistantUnrolled } from "@continuedev/config-yaml"; | |
| 2 | +import { describe, it, expect, vi, beforeEach, type MockedFunction } from "vitest"; | |
| 3 | + | |
| 4 | +import type { AuthConfig, AuthenticatedConfig } from "./auth/workos.js"; | |
| 5 | +import type { ConfigServiceState } from "./services/types.js"; | |
| 9 | 6 | import { handleSlashCommands } from "./slashCommands.js"; |
| 10 | 7 | |
| 11 | -// The imports are already mocked via vitest.setup.ts, so we can use them directly | |
| 12 | - | |
| 13 | -// Mock console to avoid output during tests | |
| 14 | -const originalConsole = console; | |
| 15 | -const mockConsole = { | |
| 16 | - info: vi.fn(), | |
| 17 | - error: vi.fn(), | |
| 18 | - log: vi.fn(), | |
| 19 | -}; | |
| 20 | - | |
| 21 | -describe("handleSlashCommands", () => { | |
| 8 | +// Mock the services | |
| 9 | +vi.mock("./services/index.js", () => ({ | |
| 10 | + services: { | |
| 11 | + config: { | |
| 12 | + getState: vi.fn() | |
| 13 | + } | |
| 14 | + }, | |
| 15 | + reloadService: vi.fn(), | |
| 16 | + SERVICE_NAMES: { | |
| 17 | + AUTH: 'AUTH' | |
| 18 | + } | |
| 19 | +})); | |
| 20 | + | |
| 21 | +// Mock auth functions | |
| 22 | +vi.mock("./auth/workos.js", () => ({ | |
| 23 | + isAuthenticated: vi.fn(), | |
| 24 | + isAuthenticatedConfig: vi.fn(), | |
| 25 | + loadAuthConfig: vi.fn() | |
| 26 | +})); | |
| 27 | + | |
| 28 | +// Mock telemetry | |
| 29 | +vi.mock("./telemetry/posthogService.js", () => ({ | |
| 30 | + posthogService: { | |
| 31 | + capture: vi.fn() | |
| 32 | + } | |
| 33 | +})); | |
| 34 | + | |
| 35 | +// Mock commands | |
| 36 | +vi.mock("./commands/commands.js", () => ({ | |
| 37 | + getAllSlashCommands: vi.fn(() => []) | |
| 38 | +})); | |
| 39 | + | |
| 40 | +// Mock os and path | |
| 41 | +vi.mock("os", () => ({ | |
| 42 | + default: { | |
| 43 | + homedir: vi.fn(() => "/home/test") | |
| 44 | + } | |
| 45 | +})); | |
| 46 | + | |
| 47 | +vi.mock("path", () => ({ | |
| 48 | + default: { | |
| 49 | + join: vi.fn((...parts) => parts.join("/")) | |
| 50 | + }, | |
| 51 | + join: vi.fn((...parts) => parts.join("/")) | |
| 52 | +})); | |
| 53 | + | |
| 54 | +// Mock session functions | |
| 55 | +vi.mock("./session.js", () => ({ | |
| 56 | + getSessionFilePath: vi.fn(() => "/home/test/.continue/cli-sessions/continue-cli-pid-12345.json"), | |
| 57 | + hasSession: vi.fn(() => false) | |
| 58 | +})); | |
| 59 | + | |
| 60 | +describe("slashCommands", () => { | |
| 22 | 61 | const mockAssistant: AssistantUnrolled = { |
| 23 | 62 | name: "test-assistant", |
| 24 | - version: "1.0.0", | |
| 25 | - prompts: [{ name: "test", prompt: "Test prompt: " }], | |
| 63 | + version: "1.0.0" | |
| 26 | 64 | }; |
| 27 | 65 | |
| 28 | 66 | beforeEach(() => { |
| 29 | - Object.assign(console, mockConsole); | |
| 30 | 67 | vi.clearAllMocks(); |
| 31 | - | |
| 32 | - // Since the mock already returns the required value, we don't need to set it | |
| 33 | - // Just verify it returns what we expect | |
| 34 | - expect(commands.getAllSlashCommands(mockAssistant)).toEqual( | |
| 35 | - expect.arrayContaining([ | |
| 36 | - expect.objectContaining({ name: "help" }), | |
| 37 | - expect.objectContaining({ name: "login" }), | |
| 38 | - ]), | |
| 39 | - ); | |
| 40 | 68 | }); |
| 41 | 69 | |
| 42 | - afterEach(() => { | |
| 43 | - Object.assign(console, originalConsole); | |
| 44 | - }); | |
| 45 | - | |
| 46 | - describe("Automatic Service Cascade Reloading", () => { | |
| 47 | - test.skip("login command should trigger automatic cascade reload via auth service", async () => { | |
| 48 | - const newAuthState: AuthServiceState = { | |
| 49 | - authConfig: { userEmail: "test@example.com" } as any, | |
| 50 | - isAuthenticated: true, | |
| 51 | - }; | |
| 52 | - | |
| 53 | - (services.auth.login as any).mockResolvedValue(newAuthState); | |
| 54 | - (workos.isAuthenticatedConfig as any).mockReturnValue(true); | |
| 55 | - (reloadService as any).mockResolvedValue(undefined); | |
| 56 | - | |
| 57 | - const result = await handleSlashCommands("/login", mockAssistant); | |
| 58 | - | |
| 59 | - expect(result).not.toBeNull(); | |
| 60 | - expect(result?.output).toContain( | |
| 61 | - "Login successful! All services updated automatically.", | |
| 62 | - ); | |
| 63 | - | |
| 64 | - // Verify auth service login was called | |
| 65 | - expect(services.auth.login).toHaveBeenCalledTimes(1); | |
| 66 | - | |
| 67 | - // Verify automatic cascade reload was triggered - only auth service reload needed | |
| 68 | - expect(reloadService).toHaveBeenCalledTimes(1); | |
| 69 | - expect(reloadService).toHaveBeenCalledWith(SERVICE_NAMES.AUTH); | |
| 70 | - | |
| 71 | - // Verify manual service reloads are NOT called | |
| 72 | - expect(reloadService).not.toHaveBeenCalledWith(SERVICE_NAMES.API_CLIENT); | |
| 73 | - expect(reloadService).not.toHaveBeenCalledWith(SERVICE_NAMES.CONFIG); | |
| 74 | - }); | |
| 75 | - | |
| 76 | - test.skip("login failure should not trigger any reloads", async () => { | |
| 77 | - const loginError = new Error("Login failed"); | |
| 78 | - (services.auth.login as any).mockRejectedValue(loginError); | |
| 79 | - | |
| 80 | - const result = await handleSlashCommands("/login", mockAssistant); | |
| 81 | - | |
| 82 | - expect(result).not.toBeNull(); | |
| 83 | - expect(result?.output).toContain("Login failed: Login failed"); | |
| 84 | - | |
| 85 | - // Verify NO reload was triggered on failure | |
| 86 | - expect(reloadService).not.toHaveBeenCalled(); | |
| 70 | + describe("handleSlashCommands", () => { | |
| 71 | + it("should handle /info command when not authenticated", async () => { | |
| 72 | + const { isAuthenticated } = await import("./auth/workos.js"); | |
| 73 | + const { services } = await import("./services/index.js"); | |
| 74 | + | |
| 75 | + (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false); | |
| 76 | + (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({ | |
| 77 | + config: null, | |
| 78 | + configPath: "/test/config.yaml" | |
| 79 | + } as ConfigServiceState); | |
| 80 | + | |
| 81 | + const result = await handleSlashCommands("/info", mockAssistant); | |
| 82 | + | |
| 83 | + expect(result).toBeDefined(); | |
| 84 | + expect(result?.output).toContain("Authentication:"); | |
| 85 | + expect(result?.output).toContain("Not logged in"); | |
| 86 | + expect(result?.output).toContain("Configuration:"); | |
| 87 | + expect(result?.output).toContain("/test/config.yaml"); | |
| 88 | + expect(result?.output).toContain("Session History:"); | |
| 89 | + expect(result?.output).toContain(".json"); | |
| 90 | + expect(result?.exit).toBe(false); | |
| 87 | 91 | }); |
| 88 | - }); | |
| 89 | 92 | |
| 90 | - describe("Other Commands (unchanged behavior)", () => { | |
| 91 | - test("help command should work normally", async () => { | |
| 92 | - const result = await handleSlashCommands("/help", mockAssistant); | |
| 93 | - | |
| 94 | - expect(result).not.toBeNull(); | |
| 95 | - expect(result?.output).toContain("Slash commands:"); | |
| 96 | - expect(result?.output).toContain("/help: Show help"); | |
| 97 | - expect(result?.output).toContain("/login: Authenticate"); | |
| 93 | + it("should handle /info command when authenticated via environment", async () => { | |
| 94 | + const { isAuthenticated, loadAuthConfig, isAuthenticatedConfig } = await import("./auth/workos.js"); | |
| 95 | + const { services } = await import("./services/index.js"); | |
| 96 | + | |
| 97 | + (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(true); | |
| 98 | + (loadAuthConfig as MockedFunction<typeof loadAuthConfig>).mockReturnValue({} as AuthConfig); | |
| 99 | + (isAuthenticatedConfig as any).mockReturnValue(false); | |
| 100 | + (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({ | |
| 101 | + config: null, | |
| 102 | + configPath: undefined | |
| 103 | + } as ConfigServiceState); | |
| 104 | + | |
| 105 | + const result = await handleSlashCommands("/info", mockAssistant); | |
| 106 | + | |
| 107 | + expect(result).toBeDefined(); | |
| 108 | + expect(result?.output).toContain("Authentication:"); | |
| 109 | + expect(result?.output).toContain("Authenticated via environment variable"); | |
| 110 | + expect(result?.output).toContain("Configuration:"); | |
| 111 | + expect(result?.output).toContain("Using default configuration"); | |
| 112 | + expect(result?.exit).toBe(false); | |
| 98 | 113 | }); |
| 99 | 114 | |
| 100 | - test.skip("logout command should exit", async () => { | |
| 101 | - const logoutState: AuthServiceState = { | |
| 102 | - authConfig: null, | |
| 103 | - isAuthenticated: false, | |
| 115 | + it("should handle /info command when authenticated with user config", async () => { | |
| 116 | + const { isAuthenticated, loadAuthConfig, isAuthenticatedConfig } = await import("./auth/workos.js"); | |
| 117 | + const { services } = await import("./services/index.js"); | |
| 118 | + | |
| 119 | + const mockAuthConfig: AuthenticatedConfig = { | |
| 120 | + userId: "test-user-id", | |
| 121 | + userEmail: "test@example.com", | |
| 122 | + accessToken: "test-token", | |
| 123 | + refreshToken: "test-refresh-token", | |
| 124 | + expiresAt: Date.now() + 3600000, | |
| 125 | + organizationId: "test-org-id" | |
| 104 | 126 | }; |
| 105 | - (services.auth.logout as any).mockResolvedValue(logoutState); | |
| 106 | - | |
| 107 | - const result = await handleSlashCommands("/logout", mockAssistant); | |
| 108 | - | |
| 109 | - expect(result).not.toBeNull(); | |
| 110 | - expect(result?.exit).toBe(true); | |
| 111 | - expect(result?.output).toContain("Logged out successfully"); | |
| 112 | - }); | |
| 113 | 127 | |
| 114 | - test("clear command should work normally", async () => { | |
| 115 | - const result = await handleSlashCommands("/clear", mockAssistant); | |
| 116 | - | |
| 117 | - expect(result).not.toBeNull(); | |
| 118 | - expect(result?.clear).toBe(true); | |
| 119 | - expect(result?.output).toBe("Chat history cleared"); | |
| 120 | - }); | |
| 121 | - | |
| 122 | - test("compact command should work normally", async () => { | |
| 123 | - const result = await handleSlashCommands("/compact", mockAssistant); | |
| 124 | - | |
| 125 | - expect(result).not.toBeNull(); | |
| 126 | - expect(result?.compact).toBe(true); | |
| 128 | + (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(true); | |
| 129 | + (loadAuthConfig as MockedFunction<typeof loadAuthConfig>).mockReturnValue(mockAuthConfig); | |
| 130 | + (isAuthenticatedConfig as any).mockReturnValue(true); | |
| 131 | + (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({ | |
| 132 | + config: null, | |
| 133 | + configPath: "/custom/config.yaml" | |
| 134 | + } as ConfigServiceState); | |
| 135 | + | |
| 136 | + const result = await handleSlashCommands("/info", mockAssistant); | |
| 137 | + | |
| 138 | + expect(result).toBeDefined(); | |
| 139 | + expect(result?.output).toContain("Authentication:"); | |
| 140 | + expect(result?.output).toContain("test@example.com"); | |
| 141 | + expect(result?.output).toContain("(no org)"); | |
| 142 | + expect(result?.output).toContain("Configuration:"); | |
| 143 | + expect(result?.output).toContain("/custom/config.yaml"); | |
| 144 | + expect(result?.exit).toBe(false); | |
| 127 | 145 | }); |
| 128 | 146 | |
| 129 | - test("resume command should open session selector", async () => { | |
| 130 | - const result = await handleSlashCommands("/resume", mockAssistant); | |
| 131 | - | |
| 132 | - expect(result).not.toBeNull(); | |
| 133 | - expect(result?.openSessionSelector).toBe(true); | |
| 134 | - }); | |
| 135 | - | |
| 136 | - test("non-slash input should return null", async () => { | |
| 137 | - const result = await handleSlashCommands("regular input", mockAssistant); | |
| 138 | - expect(result).toBeNull(); | |
| 147 | + it("should handle config service errors gracefully", async () => { | |
| 148 | + const { isAuthenticated } = await import("./auth/workos.js"); | |
| 149 | + const { services } = await import("./services/index.js"); | |
| 150 | + | |
| 151 | + (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false); | |
| 152 | + (services.config.getState as MockedFunction<typeof services.config.getState>).mockImplementation(() => { | |
| 153 | + throw new Error("Service not ready"); | |
| 154 | + }); | |
| 155 | + | |
| 156 | + const result = await handleSlashCommands("/info", mockAssistant); | |
| 157 | + | |
| 158 | + expect(result).toBeDefined(); | |
| 159 | + expect(result?.output).toContain("Configuration service not available"); | |
| 139 | 160 | }); |
| 140 | 161 | |
| 141 | - test("unknown slash command should return null", async () => { | |
| 142 | - const result = await handleSlashCommands("/unknown", mockAssistant); | |
| 143 | - | |
| 144 | - expect(result).toBeNull(); | |
| 162 | + it("should use test session directory when in test mode", async () => { | |
| 163 | + const { isAuthenticated } = await import("./auth/workos.js"); | |
| 164 | + const { services } = await import("./services/index.js"); | |
| 165 | + const { getSessionFilePath } = await import("./session.js"); | |
| 166 | + | |
| 167 | + // Mock the session path for this specific test | |
| 168 | + (getSessionFilePath as any).mockReturnValue("/test-home/.continue/cli-sessions/continue-cli-test-123.json"); | |
| 169 | + | |
| 170 | + (isAuthenticated as MockedFunction<typeof isAuthenticated>).mockReturnValue(false); | |
| 171 | + (services.config.getState as MockedFunction<typeof services.config.getState>).mockReturnValue({ | |
| 172 | + config: null, | |
| 173 | + configPath: undefined | |
| 174 | + } as ConfigServiceState); | |
| 175 | + | |
| 176 | + const result = await handleSlashCommands("/info", mockAssistant); | |
| 177 | + | |
| 178 | + expect(result?.output).toContain("/test-home/.continue/cli-sessions/"); | |
| 179 | + expect(result?.output).toContain(".json"); | |
| 145 | 180 | }); |
| 146 | 181 | }); |
| 147 | -}); | |
| 182 | +}); | |
| No newline at the end of the file |
modified extensions/cli/src/slashCommands.ts +59 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | } from "./auth/workos.js"; |
| 9 | 9 | import { getAllSlashCommands } from "./commands/commands.js"; |
| 10 | 10 | import { reloadService, SERVICE_NAMES, services } from "./services/index.js"; |
| 11 | +import { getSessionFilePath } from "./session.js"; | |
| 11 | 12 | import { posthogService } from "./telemetry/posthogService.js"; |
| 12 | 13 | import { SlashCommandResult } from "./ui/hooks/useChat.types.js"; |
| 13 | 14 | |
| @@ -96,6 +97,63 @@ | ||
| 96 | 97 | } |
| 97 | 98 | } |
| 98 | 99 | |
| 100 | +async function handleInfo() { | |
| 101 | + posthogService.capture("useSlashCommand", { name: "info" }); | |
| 102 | + | |
| 103 | + const infoLines = []; | |
| 104 | + | |
| 105 | + // Auth info | |
| 106 | + if (isAuthenticated()) { | |
| 107 | + const config = loadAuthConfig(); | |
| 108 | + if (config && isAuthenticatedConfig(config)) { | |
| 109 | + const email = config.userEmail || config.userId; | |
| 110 | + const org = "(no org)"; // Organization info not available in AuthenticatedConfig | |
| 111 | + infoLines.push(chalk.white("Authentication:")); | |
| 112 | + infoLines.push(` Email: ${chalk.green(email)}`); | |
| 113 | + infoLines.push(` Organization: ${chalk.cyan(org)}`); | |
| 114 | + } else { | |
| 115 | + infoLines.push(chalk.white("Authentication:")); | |
| 116 | + infoLines.push( | |
| 117 | + ` ${chalk.yellow("Authenticated via environment variable")}`, | |
| 118 | + ); | |
| 119 | + } | |
| 120 | + } else { | |
| 121 | + infoLines.push(chalk.white("Authentication:")); | |
| 122 | + infoLines.push(` ${chalk.red("Not logged in")}`); | |
| 123 | + } | |
| 124 | + | |
| 125 | + // Config info | |
| 126 | + try { | |
| 127 | + const configState = services.config.getState(); | |
| 128 | + infoLines.push(""); | |
| 129 | + infoLines.push(chalk.white("Configuration:")); | |
| 130 | + if (configState.config) { | |
| 131 | + infoLines.push(` ${chalk.gray(`Using ${configState.config?.name}`)}`); | |
| 132 | + } else { | |
| 133 | + infoLines.push(` ${chalk.red(`Config not found`)}`); | |
| 134 | + } | |
| 135 | + if (configState.configPath) { | |
| 136 | + infoLines.push(` Path: ${chalk.blue(configState.configPath)}`); | |
| 137 | + } | |
| 138 | + } catch { | |
| 139 | + infoLines.push(""); | |
| 140 | + infoLines.push(chalk.white("Configuration:")); | |
| 141 | + infoLines.push(` ${chalk.red("Configuration service not available")}`); | |
| 142 | + } | |
| 143 | + | |
| 144 | + // Session history path | |
| 145 | + infoLines.push(""); | |
| 146 | + infoLines.push(chalk.white("Session History:")); | |
| 147 | + const sessionFilePath = getSessionFilePath(); | |
| 148 | + | |
| 149 | + infoLines.push(` File: ${chalk.blue(sessionFilePath)}`); | |
| 150 | + | |
| 151 | + return { | |
| 152 | + exit: false, | |
| 153 | + output: infoLines.join("\n"), | |
| 154 | + }; | |
| 155 | +} | |
| 156 | + | |
| 99 | 157 | const commandHandlers: Record<string, CommandHandler> = { |
| 100 | 158 | help: handleHelp, |
| 101 | 159 | clear: () => { |
| @@ -113,6 +171,7 @@ | ||
| 113 | 171 | login: handleLogin, |
| 114 | 172 | logout: handleLogout, |
| 115 | 173 | whoami: handleWhoami, |
| 174 | + info: handleInfo, | |
| 116 | 175 | model: () => ({ openModelSelector: true }), |
| 117 | 176 | compact: () => { |
| 118 | 177 | posthogService.capture("useSlashCommand", { name: "compact" }); |