continue-custom/extensions/cli/src/test-helpers
2025-11-18 19:45:15 -08:00
..
__tests__ chore: run prettier --write on cli 2025-08-20 17:57:35 -07:00
adapter-mocks.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
cli-helpers.ts feat: ✨ Remove TTY requirement for the cli in headless mode 2025-11-18 19:45:15 -08:00
mock-helpers.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
mock-llm-server.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
README.md Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
renderWithServices.tsx Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
testServiceContainer.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
ui-test-context-minimal.ts Add 'extensions/cli/' from commit 'e27a5c87d520e28844c9eac10bc6d301feee4b5e' 2025-08-20 17:19:56 -07:00
ui-test-context.ts refactor: phase 2 2025-09-01 12:00:43 -07:00

Test Helpers

This directory contains helper functions for testing the Continue CLI.

Mock LLM Server

The 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.

Basic Usage

import {
  setupMockLLMTest,
  cleanupMockLLMServer,
} from "../test-helpers/mock-llm-server.js";

describe("My Test", () => {
  let context: any;
  let mockServer: MockLLMServer;

  beforeEach(async () => {
    context = await createTestContext();
    mockServer = await setupMockLLMTest(context, {
      response: "Hello from mock LLM!",
    });
  });

  afterEach(async () => {
    await cleanupMockLLMServer(mockServer);
    await cleanupTestContext(context);
  });

  it("should get response from mock", async () => {
    const result = await runCLI(context, {
      args: ["-p", "Test prompt", "--config", context.configPath],
    });
    expect(result.stdout).toContain("Hello from mock LLM!");
  });
});

Advanced Usage

Dynamic Responses

mockServer = await setupMockLLMTest(context, {
  response: (prompt: string) => {
    if (prompt.includes("weather")) {
      return "It's sunny!";
    }
    return "Default response";
  },
});

Non-Streaming Responses

mockServer = await setupMockLLMTest(context, {
  response: "Non-streaming response",
  streaming: false, // Sends entire response at once instead of word-by-word
});

Note: 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.

Custom Request Handling

const mockServer = await createMockLLMServer({
  customHandler: (req, res) => {
    // Custom logic here
    res.writeHead(200);
    res.end("Custom response");
  },
});

Request Tracking

The mock server tracks all requests it receives:

// After making requests...
expect(mockServer.requests).toHaveLength(1);
expect(mockServer.requests[0].body.messages[0].content).toBe("User prompt");

API Reference

setupMockLLMTest(context, options)

Sets up a complete test environment with mock LLM server, config file, and skips onboarding.

createMockLLMServer(options)

Creates just the mock server without test environment setup.

createMockLLMConfig(mockServer, modelName)

Generates a config YAML string for the mock server.

cleanupMockLLMServer(mockServer)

Properly shuts down the mock server.