Elffuss BraidHub

kikocis/continue public

main · 2.5 KiBRenderedRawPermalink
1# Test Helpers
2
3This directory contains helper functions for testing the Continue CLI.
4
5## Mock LLM Server
6
7The `mock-llm-server.ts` module provides utilities for creating mock LLM servers in tests. This allows you to test the CLI's behavior without making real API calls.
8
9### Basic Usage
10
11```typescript
12import {
13 setupMockLLMTest,
14 cleanupMockLLMServer,
15} from "../test-helpers/mock-llm-server.js";
16
17describe("My Test", () => {
18 let context: any;
19 let mockServer: MockLLMServer;
20
21 beforeEach(async () => {
22 context = await createTestContext();
23 mockServer = await setupMockLLMTest(context, {
24 response: "Hello from mock LLM!",
25 });
26 });
27
28 afterEach(async () => {
29 await cleanupMockLLMServer(mockServer);
30 await cleanupTestContext(context);
31 });
32
33 it("should get response from mock", async () => {
34 const result = await runCLI(context, {
35 args: ["-p", "Test prompt", "--config", context.configPath],
36 });
37 expect(result.stdout).toContain("Hello from mock LLM!");
38 });
39});
40```
41
42### Advanced Usage
43
44#### Dynamic Responses
45
46```typescript
47mockServer = await setupMockLLMTest(context, {
48 response: (prompt: string) => {
49 if (prompt.includes("weather")) {
50 return "It's sunny!";
51 }
52 return "Default response";
53 },
54});
55```
56
57#### Non-Streaming Responses
58
59```typescript
60mockServer = await setupMockLLMTest(context, {
61 response: "Non-streaming response",
62 streaming: false, // Sends entire response at once instead of word-by-word
63});
64```
65
66Note: The CLI always expects SSE format, so responses are always sent as streaming events. The `streaming` option only controls whether the response is chunked word-by-word or sent all at once.
67
68#### Custom Request Handling
69
70```typescript
71const mockServer = await createMockLLMServer({
72 customHandler: (req, res) => {
73 // Custom logic here
74 res.writeHead(200);
75 res.end("Custom response");
76 },
77});
78```
79
80#### Request Tracking
81
82The mock server tracks all requests it receives:
83
84```typescript
85// After making requests...
86expect(mockServer.requests).toHaveLength(1);
87expect(mockServer.requests[0].body.messages[0].content).toBe("User prompt");
88```
89
90### API Reference
91
92#### `setupMockLLMTest(context, options)`
93
94Sets up a complete test environment with mock LLM server, config file, and skips onboarding.
95
96#### `createMockLLMServer(options)`
97
98Creates just the mock server without test environment setup.
99
100#### `createMockLLMConfig(mockServer, modelName)`
101
102Generates a config YAML string for the mock server.
103
104#### `cleanupMockLLMServer(mockServer)`
105
106Properly shuts down the mock server.