Skip to content

Commit 45cace7

Browse files
committed
fix: 🐛 More fixes to tests
1 parent 32a5093 commit 45cace7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

extensions/cli/src/commands/chat.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,16 @@ async function runHeadlessMode(
495495
// Critical validation: Ensure we have actual prompt text in headless mode
496496
// This prevents the CLI from hanging in TTY-less environments when question() is called
497497
// We check AFTER processing all prompts (including agent files) to ensure we have real content
498+
// EXCEPTION: Allow empty prompts when resuming/forking since they may just want to view history
498499
if (!initialUserInput || !initialUserInput.trim()) {
500+
// If resuming or forking, allow empty prompt - just exit successfully after showing history
501+
if (options.resume || options.fork) {
502+
// For resume/fork with no new input, we've already loaded the history above
503+
// Just exit successfully (the history was already loaded into chatHistory)
504+
await gracefulExit(0);
505+
return;
506+
}
507+
499508
throw new Error(
500509
'Headless mode requires a prompt. Use: cn -p "your prompt"\n' +
501510
'Or pipe input: echo "prompt" | cn -p\n' +

extensions/cli/src/e2e/resume-flag.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
runCLI,
88
} from "../test-helpers/cli-helpers.js";
99
import {
10-
setupMockLLMTest,
1110
cleanupMockLLMServer,
11+
setupMockLLMTest,
1212
type MockLLMServer,
1313
} from "../test-helpers/mock-llm-server.js";
1414

@@ -80,8 +80,9 @@ describe("E2E: Resume Flag", () => {
8080
expect(assistantMessage?.message?.content).toBe("Hello! Nice to meet you.");
8181

8282
// Now run with --resume flag using the same session ID
83+
// Use -p flag to run in headless mode (tests don't have TTY)
8384
const resumeResult = await runCLI(context, {
84-
args: ["--resume", "--config", context.configPath],
85+
args: ["-p", "--resume", "--config", context.configPath],
8586
env: {
8687
CONTINUE_CLI_TEST_SESSION_ID: "test-session-123",
8788
CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"),
@@ -98,8 +99,9 @@ describe("E2E: Resume Flag", () => {
9899

99100
it("should handle --resume when no previous session exists", async () => {
100101
// Try to resume without any previous session
102+
// Use -p flag to run in headless mode (tests don't have TTY)
101103
const result = await runCLI(context, {
102-
args: ["--resume", "--config", context.configPath],
104+
args: ["-p", "--resume", "--config", context.configPath],
103105
env: {
104106
CONTINUE_CLI_TEST_SESSION_ID: "no-session-456",
105107
CONTINUE_GLOBAL_DIR: path.join(context.testDir, ".continue"),

extensions/cli/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,19 @@ addCommonOptions(program)
216216
}
217217
}
218218

219-
// In headless mode, ensure we have a prompt unless using --agent flag
220-
// Agent files can provide their own prompts
221-
if (options.print && !prompt && !options.agent) {
219+
// In headless mode, ensure we have a prompt unless using --agent flag or --resume flag
220+
// Agent files can provide their own prompts, and resume can work without new input
221+
if (options.print && !prompt && !options.agent && !options.resume) {
222222
safeStderr(
223-
"Error: A prompt is required when using the -p/--print flag, unless --prompt or --agent is provided.\n\n",
223+
"Error: A prompt is required when using the -p/--print flag, unless --prompt, --agent, or --resume is provided.\n\n",
224224
);
225225
safeStderr("Usage examples:\n");
226226
safeStderr(' cn -p "please review my current git diff"\n');
227227
safeStderr(' echo "hello" | cn -p\n');
228228
safeStderr(' cn -p "analyze the code in src/"\n');
229229
safeStderr(" cn -p --agent my-org/my-agent\n");
230230
safeStderr(" cn -p --prompt my-org/my-prompt\n");
231+
safeStderr(" cn -p --resume\n");
231232
await gracefulExit(1);
232233
}
233234

0 commit comments

Comments
 (0)