fix: 🐛 More fixes to tests

This commit is contained in:
Shawn Smith 2025-11-11 20:45:38 -08:00
parent 0a04fa8672
commit ad283ee46e
3 changed files with 19 additions and 7 deletions

View file

@ -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' +

View file

@ -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"),

View file

@ -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);
}