From ad283ee46e82b02a2ce9e7f334803cbd9f83c9dd Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Tue, 11 Nov 2025 20:45:38 -0800 Subject: [PATCH] fix: :bug: More fixes to tests --- extensions/cli/src/commands/chat.ts | 9 +++++++++ extensions/cli/src/e2e/resume-flag.test.ts | 8 +++++--- extensions/cli/src/index.ts | 9 +++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/extensions/cli/src/commands/chat.ts b/extensions/cli/src/commands/chat.ts index e907f7e66..71c1d53a4 100644 --- a/extensions/cli/src/commands/chat.ts +++ b/extensions/cli/src/commands/chat.ts @@ -495,7 +495,16 @@ async function runHeadlessMode( // Critical validation: Ensure we have actual prompt text in headless mode // This prevents the CLI from hanging in TTY-less environments when question() is called // We check AFTER processing all prompts (including agent files) to ensure we have real content + // EXCEPTION: Allow empty prompts when resuming/forking since they may just want to view history if (!initialUserInput || !initialUserInput.trim()) { + // If resuming or forking, allow empty prompt - just exit successfully after showing history + if (options.resume || options.fork) { + // For resume/fork with no new input, we've already loaded the history above + // Just exit successfully (the history was already loaded into chatHistory) + await gracefulExit(0); + return; + } + throw new Error( 'Headless mode requires a prompt. Use: cn -p "your prompt"\n' + 'Or pipe input: echo "prompt" | cn -p\n' + diff --git a/extensions/cli/src/e2e/resume-flag.test.ts b/extensions/cli/src/e2e/resume-flag.test.ts index 910890b7d..e18969c20 100644 --- a/extensions/cli/src/e2e/resume-flag.test.ts +++ b/extensions/cli/src/e2e/resume-flag.test.ts @@ -7,8 +7,8 @@ import { runCLI, } from "../test-helpers/cli-helpers.js"; import { - setupMockLLMTest, cleanupMockLLMServer, + setupMockLLMTest, type MockLLMServer, } from "../test-helpers/mock-llm-server.js"; @@ -80,8 +80,9 @@ describe("E2E: Resume Flag", () => { expect(assistantMessage?.message?.content).toBe("Hello! Nice to meet you."); // Now run with --resume flag using the same session ID + // Use -p flag to run in headless mode (tests don't have TTY) const resumeResult = await runCLI(context, { - args: ["--resume", "--config", context.configPath], + args: ["-p", "--resume", "--config", context.configPath], env: { CONTINUE_CLI_TEST_SESSION_ID: "test-session-123", CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"), @@ -98,8 +99,9 @@ describe("E2E: Resume Flag", () => { it("should handle --resume when no previous session exists", async () => { // Try to resume without any previous session + // Use -p flag to run in headless mode (tests don't have TTY) const result = await runCLI(context, { - args: ["--resume", "--config", context.configPath], + args: ["-p", "--resume", "--config", context.configPath], env: { CONTINUE_CLI_TEST_SESSION_ID: "no-session-456", CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"), diff --git a/extensions/cli/src/index.ts b/extensions/cli/src/index.ts index b1aa39c28..4735f416f 100644 --- a/extensions/cli/src/index.ts +++ b/extensions/cli/src/index.ts @@ -216,11 +216,11 @@ addCommonOptions(program) } } - // In headless mode, ensure we have a prompt unless using --agent flag - // Agent files can provide their own prompts - if (options.print && !prompt && !options.agent) { + // In headless mode, ensure we have a prompt unless using --agent flag or --resume flag + // Agent files can provide their own prompts, and resume can work without new input + if (options.print && !prompt && !options.agent && !options.resume) { safeStderr( - "Error: A prompt is required when using the -p/--print flag, unless --prompt or --agent is provided.\n\n", + "Error: A prompt is required when using the -p/--print flag, unless --prompt, --agent, or --resume is provided.\n\n", ); safeStderr("Usage examples:\n"); safeStderr(' cn -p "please review my current git diff"\n'); @@ -228,6 +228,7 @@ addCommonOptions(program) safeStderr(' cn -p "analyze the code in src/"\n'); safeStderr(" cn -p --agent my-org/my-agent\n"); safeStderr(" cn -p --prompt my-org/my-prompt\n"); + safeStderr(" cn -p --resume\n"); await gracefulExit(1); }