Elffuss BraidHub

kikocis/continue public

57d99ced5e24 · 2.1 KiBRawPermalink
1import {
2 cleanupTestContext,
3 createTestContext,
4 runCLI,
5} from "../test-helpers/cli-helpers.js";
6import {
7 setupMockLLMTest,
8 cleanupMockLLMServer,
9 type MockLLMServer,
10} from "../test-helpers/mock-llm-server.js";
11
12describe("E2E: Headless Mode with Mock Server", () => {
13 let context: any;
14 let mockServer: MockLLMServer;
15
16 beforeEach(async () => {
17 context = await createTestContext();
18 mockServer = await setupMockLLMTest(context, {
19 response: "Hello World!",
20 });
21 });
22
23 afterEach(async () => {
24 await cleanupMockLLMServer(mockServer);
25 await cleanupTestContext(context);
26 });
27
28 it('should output "Hello World!" when using cn -p "Hi"', async () => {
29 const result = await runCLI(context, {
30 args: ["-p", "--config", context.configPath, "Hi"],
31 timeout: 15000,
32 });
33
34 // Verify stdout contains "Hello World!"
35 expect(result.stdout).toContain("Hello World!");
36 expect(result.exitCode).toBe(0);
37 }, 20000);
38
39 it("should handle streaming responses correctly", async () => {
40 const result = await runCLI(context, {
41 args: ["-p", "--config", context.configPath, "Say hello"],
42 timeout: 15000,
43 });
44
45 expect(result.stdout).toContain("Hello World!");
46 expect(result.exitCode).toBe(0);
47 expect(mockServer.requests).toHaveLength(1);
48 // Find the user message (system message is first)
49 const userMessage = mockServer.requests[0].body.messages.find((m: any) => m.role === "user");
50 expect(userMessage.content).toBe("Say hello");
51 }, 20000);
52
53 it("should work with longer prompts", async () => {
54 const result = await runCLI(context, {
55 args: ["-p", "--config", context.configPath, "Please respond with exactly 'Hello World!' and nothing else"],
56 timeout: 15000,
57 });
58
59 expect(result.stdout).toContain("Hello World!");
60 expect(result.exitCode).toBe(0);
61 expect(mockServer.requests).toHaveLength(1);
62 // Find the user message (system message is first)
63 const userMessage = mockServer.requests[0].body.messages.find((m: any) => m.role === "user");
64 expect(userMessage.content).toBe("Please respond with exactly 'Hello World!' and nothing else");
65 }, 20000);
66});